Quill编辑器将样式应用于文本

时间:2016-07-01 13:02:29

标签: quill

我在primeng编辑器中使用quill编辑器。我想在输入时对文本应用样式(文本更改)。当我在斜杠中键入文本时,我可能必须应用样式,并且应删除2个斜杠。 例如: 我使用/ quill /编辑器。 这应该是:我使用 quill 编辑器。

仅在斜杠内的文本应该应用样式。除了斜杠中的文本不应该应用于样式。

我已将以下代码添加到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();

        }
    }

但问题突出显示一个文字,文字输入后突出显示(粗体)。在突出显示文本后,我无法停止突出显示文本,然后所有文本将在突出显示文本后突出显示。请帮助我。

1 个答案:

答案 0 :(得分:0)

您可以使用formatText将格式应用于任意文本范围。如果您使用的是Quill 1.0测试版,contextual keyboard handlers可以让您更轻松。

相关问题