【问题标题】:Code highlighter not working in the quill editor代码荧光笔在羽毛笔编辑器中不起作用
【发布时间】:2020-03-02 23:16:16
【问题描述】:

我遵循了 Quill 的文档,但是语法高亮不起作用。顺便说一句,即使Quill playground webpage 上的示例也不起作用,而Quill home page 上的示例正在运行。这是我的代码和 CodePen 的链接。

HTML

<div id="editor-container"><pre>for(int i=0;i<10;i++)
  printf ("Hello");</pre>
</div>

JS

var quill = new Quill('#editor-container', {
  modules: {
    toolbar: [
      [{ header: [1, 2, false] }],
      ['bold', 'italic', 'underline'],
      ['image', 'code-block']
    ]
  },
  placeholder: 'Compose an epic...',
  theme: 'snow'  // or 'bubble'
});

这是一个显示问题的 CodePen: https://codepen.io/imabot2/pen/mdJwdZy

【问题讨论】:

    标签: javascript quill


    【解决方案1】:

    您需要包含Syntax Highlighter Module

    包括HighLightJs

    <!-- Local file -->
    <script href="highlight.js"></script>
    
    <!-- CloudFare CDN -->
    <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.1/highlight.min.js"></script>
    

    启用模块;

    var quill = new Quill('#editor-container', {
        modules: {
            syntax: true,                          # <-- Enable module
            toolbar: [
                [{ header: [1, 2, false] }],
                ['bold', 'italic', 'underline'],
                ['image', 'code-block']
            ]
        },
        placeholder: 'Compose an epic...',
        theme: 'snow'  // or 'bubble'
    });
    

    更新了codePen; https://codepen.io/0stone0/pen/poJwBzw

    【讨论】:

    • 不起作用。未应用颜色
    • 你使用什么浏览器@SergeyOrlov?笔在最近的 Chrome 中被着色...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-22
    • 2020-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-07
    • 1970-01-01
    相关资源
    最近更新 更多