vuejs / vetur

Vue tooling for VS Code.
https://vuejs.github.io/vetur/
MIT License
5.75k stars 593 forks source link

self-closing custom tags #1792

Open michaelkryukov opened 4 years ago

michaelkryukov commented 4 years ago

Good day. I have code in my project that uses custom i18n tag:

<i18n src="~/lang/components/layouts/FormLayout.yml"/>

It highlights incorrectly, because grammar don't create single-line versions of custom tags (as far as i understood). I updated client/grammar.js to create versions for my use-case, and it working fine:

function makePatterns(tag, scope) {
    return JSON.parse(`
[
  {
    "begin": "(<)(${tag})(?=[^$\\n]*/>)",
    "beginCaptures": {
        "1": {
            "name": "punctuation.definition.tag.begin.html"
        },
        "2": {
            "name": "entity.name.tag.style.html"
        }
    },
    "end": "(/>).*$",
    "endCaptures": {
        "1": {
           "name": "punctuation.definition.tag.end.html"
        }
    },
    "patterns": [
        {
            "include": "#tag-stuff"
        }
    ]
  }
  // Unchanged old pattern here
]`);
}
michaelkryukov commented 4 years ago

Also, it would be nice if I could specify 'coffee' as 'coffeescript' in the lang attribute of the script tag. Are there any options for that?

octref commented 4 years ago

Also, it would be nice if I could specify 'coffee' as 'coffeescript' in the lang attribute of the script tag. Are there any options for that?

Not really, AFAIK the community convention is to use coffee and you should follow that.

{
  "vetur.grammar.customBlocks": {
    "type": "object",
    "default": {
      "docs": "md",
      "i18n": "json"
    },
    "description": "Mapping from custom block tag name to language name. Used for generating grammar to support syntax highlighting for custom blocks."
  }
}

I'd be ok to allow { "i18n": { language: "json", selfClosing: true } }, with selfClosing being optional and default to false.

Contribution welcome.