-
-
Notifications
You must be signed in to change notification settings - Fork 594
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
Add template literal (jsx) support #49
Comments
It's possible by modding the js grammar that comes with VSCode, so it embeds html grammar. I'll look into that a bit later. One question: is there anyway to tell whether the js file is a vue component? For react support in VSCode, VSCode uses jsx/tsx to denote support for jsx literal. |
Unfortunately Vue components are exported as standard js objects in standard js files. Could this be opt in for all js files? Thanks |
Even if it's opt-in, I can't just mark everything in backtick as html, right? |
Template literals can contain plain strings, variables wrapped in ${} and html; https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Template_literals I don't know anything about how the VSCode grammar stuff works to answer whether that would cause an issue. |
How to know stuff between backstick is html but not plain string? If there is no way to check, I can't blindly mark everything between backstick as html. |
Since HTML itself supports plain strings I'm not sure I see the issue? If it helps Vue components are required to have a single root element so ignoring whitespace they would always start and finish with a tag e.g |
This will take a lot of time to get right. I'll take a look after #26. |
Taking my words back -- this seems to be an interesting addition, and can be reused for other framework support, like how people in React is doing inlining CSS with string literals. I'll try to have it by May for 1.0 release. |
We can hard code
as the start of template literal. So only specific string literal is highlighted. Angular has implemented template completion by Angular Language Service as a tsserver plugin. While it is doable, I don't think it is easy to implement well, if it worth implementing at all. |
hey guys, |
That's blocked by an upstream issue: microsoft/vscode#44056 |
I modified a sample vscode plugin and made it look for the "html-tagged-template": {
"begin": "(?<=template: `)", "end": "(?=`)",
"contentName": "meta.embedded.html",
"patterns": [
{
"include": "#html-template-body"
}
]
} It's a quick-and-dirty solution that probably doesn't address every edge case, but I've been pretty happy with it so far. |
I have this working in javascript files using commenting.. either through Both require marking up your template literal.. which honestly I think makes sense. You could have template literals not meant to be HTML for sure.. but the notion of placing a comment in front of the backtick to denote the intended syntax is (to me) a reasonable standard:
I just added the first plugin (comment-tagged-templates) but found it doesn't work in Vue files... but wondered if there's a way to configure it to work through Vetur. @segphault how did you set your "workingness" up exactly? Was it a matter of forking/cloning that repo and editing it specifically with the options you posted and then installing it as a VSCode plugin? |
I'm very keen to get this working in Sublime- has anyone had success? |
It's common in GraphQL-land to hint tooling by tagging the literals. Perhaps Something like: export default {
template: vue`...`
} May need to import a lib that defines the |
@Patcher56 Would you be interested in taking this issue? |
I'm very busy atm but I am very interested. If I have more time, I will do that for sure! |
Any other news on this issue? One use case for this feature is writing Vue stories in Storybook. Tried using es6-string-html but it has no autocompletion, not even for basic html tags. styled-components has an extension for CSS rules with highlighting and intellisense, maybe it can be used as inspiration. |
A workaround for people which are still interested could be to use the vscode extension https://marketplace.visualstudio.com/items?itemName=plievone.vscode-template-literal-editor. You can select the template literal, press ctrl + enter and a second editor opens. Remarks: I'm not the author of this extension nor affiliated. |
Is it possible to add syntax highlighting support to template literals when not using .vue files.
The text was updated successfully, but these errors were encountered: