代码之家  ›  专栏  ›  技术社区  ›  jcubic

SVG代码镜像完成

  •  2
  • jcubic  · 技术社区  · 6 年前

    我正在尝试为codemarror创建svg模式(至少要有一个起点)。我复制了htmlmixed模式,并用svg替换了html(因为它是相同的,只有不同的完成方式)

    我还删除了所有html标记,并将其改为(在提示中):

      var s = { attrs: {} }; // Simple tag, reused for a whole lot of tags
    
      var data = {
          svg: {
              attrs: {
                  width: null, height: null, viewBox: null
              }
          },
          g: s
      };
    
      var globalAttrs = {
        id: null,
        'class': null,
        lang: ["en", "es"],
        style: null
      };
    

    但是当我打字的时候 <sv <svg wid 和媒体 ctrl+空格键 我还没有完成。我做错了什么?

    我正在从文本区域创建编辑器:

    var text = document.querySelector('textarea');
    var myCodeMirror = CodeMirror.fromTextArea(text, {
        mode:  "svg",
        extraKeys: {"Ctrl-Space": "autocomplete"},
    });
    

    这是我的 CodePen demo 是的。

    如果我把模式改成htmlmixed完成工作。

    1 回复  |  直到 6 年前
        1
  •  1
  •   Sam Denty zneak    6 年前

    这个 Codemirror.registerHelper("hint", name) name参数与模式名不关联。您可以重写autocomplete函数,并调用它 showHint 以下内容:

    CodeMirror.commands.autocomplete = function(cm) {
      CodeMirror.showHint(cm, CodeMirror.hint.name) // name being the name you passed to registerHelper
    }
    

    另外,回调 Codemirror.registerHelper("hint", name, callback) 应该返回一个对象,而不是函数。

    Updated CodePen

    推荐文章