bungcip / better-toml

toml extension for vs code editor
74 stars 13 forks source link

Inject into text.html.markdown to support fenced code blocks #29

Open bolinfest opened 4 years ago

bolinfest commented 4 years ago

https://github.com/bungcip/better-toml/issues/10 added support for "front matter" syntax highlighting in Markdown files. I'm not that familiar with it, but I see it is some sort of metadata format that must appear at the start of a file: https://jekyllrb.com/docs/front-matter/.

For the rest of us, I think the more interesting injection into the Markdown grammar would be for fenced code blocks. This is what makes it possible to write a triple-backtick followed by a programming language and get it syntax-highlighted properly like so:

```js
function example() {
  return "This would be highlighted as JavaScript in a Markdown file.";
}
```

Unfortunately, this does not work with the TOML extension today:

```toml
key = "This is not syntax highlighted as TOML in a Markdown file in VS Code today."
```

Here are examples of how other VS Code extensions provide this functionality:

The Haskell example has some extra checks beyond the Kotlin one (with the begin/while bits), though I haven't worked out what edge cases those are trying to address. I think porting the Kotlin example (include the additional entry in the grammars list in the package.json) would probably work well enough for now, though.