-
Notifications
You must be signed in to change notification settings - Fork 227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Syntax highlight for multiline string filled with code #714
Comments
A potentially useful idea for an alternative implementation is to use the So for example, with this schema: {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"foo": {
"title": "Foo",
"description": "A non-markdown string",
"type": "string"
},
"some_markdown": {
"title": "Some Markdown",
"description": "The text of this property is always treated as markdown",
"type": "string",
"contentMediaType": "text/markdown"
}
}
} This YAML file would have the foo: This highlights normally (i.e. it _doesn't_)
some_markdown: |
This highlights as `markdown`. This would only work with defined media types, which is a limited list and mostly doesn't include code, but I often find myself wishing my markdown strings in yaml at least had highlighting. I think the shebang idea would be useful. It's also worth noting that, for GHA files in particular, the GitHub Action extension itself could provide highlighting with injection grammar, since that extension isn't trying to support arbitrary YAML files with a schema. There's also an issue filed in that repo for this same feature. |
Does anyone know if comments are included in the YAML AST and, if so, if they could be used as a hint for syntax highlighter? For example, I was thinking of #lang=sh
foo: |
echo hi
#lang=js
bar: |
console.log('hi') I like the shebang idea, but I feel that would require O(n) in number of supported languages. I also like the media type approach. It would provide a way to configure it for some use cases. However, I do like the idea of an in-document hint. Again, I have no idea about how the YAML AST (and dependent on the parser I guess) handles the comment token in my proposal. Context: Thinking about this for GitHub workflows/actions specifically. Edit: Hypothetically, the #lang=sh
baz: >-
command
with
args
#lang=js
qux: console.log('hi') |
I came across Volar.js which seeks to simplify "embedded languages" concept. I also found their (1.5 year ago) blog post interesting: Volar: a New Beginning. Sharing in case it or its concept inspires others for solutioning. 🤞🏻 |
Is your enhancement related to a problem? Please describe.
It's pretty common to use a YAML file having a multiline string filled with code.
For instance, when is working with GitHub Actions, the
run
field can be filled with a shell script code:But since there is no way to use this extension and have syntax highlight on this part, it became monochrome.
It's okayish for simple code, but it makes harder to read a more complex code:
Describe the solution you would like
We can read the first line for a multiline string and check if there is a shebang.
If there is one, it imports the syntax highlight for the given language.
The text was updated successfully, but these errors were encountered: