2016-07-01 24 views
0

我在primeng編輯器內使用羽毛編輯器。我想在輸入文本的同時對文本應用樣式(文本更改)。當我在斜槓內輸入文本時,可能需要應用樣式,應刪除2個斜線。例如: : 我正在使用/套筒/編輯器。 這應該是:我正在使用羽毛筆編輯器。羽毛編輯器應用樣式到文本

只在斜線內的文字應該應用樣式。除了斜槓內的文本不應該應用於樣式。

我加入以下代碼Editor.ts

this.quill.on('text-change', (delta, source) => { 
      if (source == 'user') { 
      this.highlightText(); 
      this.selfChange = true; 
      let htmlValue = this.quill.getHTML(); 
      if (htmlValue == '<div><br></div>') { 
       htmlValue = null; 
      } 

      this.onTextChange.emit({ 
       htmlValue: htmlValue, 
       textValue: this.quill.getText(), 
       delta: delta, 
       source: source 
      }); 
      //if (this.selfChange) 
      this.onModelChange(htmlValue); 
      // } 
     }); 

highlightText() { 
     var text = this.quill.getText(), 
      hashRegex1 = /\/[a-zA-Z\.\*\&\s\d]*\//ig, 
      match; 

     // Try to clear all cssClass formats 
     this.quill.formatText(0, this.quill.getLength(), 'cssClass', false); 

     while (match = hashRegex1.exec(text)) { 
      this.quill.formatText(match.index, match.index + match[0].length, 'cssClass', 'test'); 
      this.quill.deleteText(match.index, match.index + 1); 
      var textLenth = match[0].length - 2; 
      this.quill.deleteText(match.index + textLenth, match.index + textLenth + 1); 
      this.quill.prepareFormat('bold', false); 
      this.quill.focus(); 

     } 
    } 

但問題是,一旦高亮文本,下面的文本進入是越來越突出顯示(黑體)。突出顯示文本後,我無法停止突出顯示文本,所有文本在突出顯示文本後都會突出顯示。請幫助我。

回答