Skip to content
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

Open
dansullivan86 opened this issue Feb 21, 2017 · 21 comments
Open

Add template literal (jsx) support #49

dansullivan86 opened this issue Feb 21, 2017 · 21 comments

Comments

@dansullivan86
Copy link

Is it possible to add syntax highlighting support to template literals when not using .vue files.

{
    template: `
    <div :class="['loading', {'loading-dark': dark, 'loading-small': small}]">
        <i class="fa fa-spinner fa-pulse"></i>
    </div>
    `,
    props: {
        dark: {
            type: Boolean,
            default: false
        },
        small: {
            type: Boolean,
            default: false
        }
    }
};
@octref
Copy link
Member

octref commented Feb 21, 2017

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.

@dansullivan86
Copy link
Author

Unfortunately Vue components are exported as standard js objects in standard js files.

Could this be opt in for all js files?

Thanks

@octref
Copy link
Member

octref commented Feb 21, 2017

Even if it's opt-in, I can't just mark everything in backtick as html, right?

@dansullivan86
Copy link
Author

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.

@octref
Copy link
Member

octref commented Feb 21, 2017

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.

@dansullivan86
Copy link
Author

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 <div></div>

@octref
Copy link
Member

octref commented Feb 21, 2017

This will take a lot of time to get right. I'll take a look after #26.

@octref
Copy link
Member

octref commented Mar 27, 2017

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.

@octref
Copy link
Member

octref commented Apr 12, 2017

@octref octref mentioned this issue May 8, 2017
12 tasks
@octref
Copy link
Member

octref commented Aug 5, 2017

ng

Alright, I thought angular already have this so I was bookmarking their LS.
Turns out they have neither syntax highlighting nor intelligent completion for inline html template.

This is a hard feature to support.

@HerringtonDarkholme
Copy link
Member

HerringtonDarkholme commented Aug 16, 2017

We can hard code

/template:\s*`/

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.

@yozman
Copy link

yozman commented Feb 23, 2018

hey guys,
when will we get this feature?
@HerringtonDarkholme @octref
I just want highlight

@octref
Copy link
Member

octref commented Feb 23, 2018

That's blocked by an upstream issue: microsoft/vscode#44056

@octref octref added the upstream label Mar 7, 2018
@segphault
Copy link

I modified a sample vscode plugin and made it look for the template: property so that I could get highlighting on my Vue templates:

"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.

@thedamon
Copy link

thedamon commented Jan 13, 2019

I have this working in javascript files using commenting.. either through
https://github.com/mjbvz/vscode-comment-tagged-templates
or (this is a bit more specific to lit-html) https://github.com/mjbvz/vscode-lit-html

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:

const template = /* html */`
   <div class="template"></div>
`

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?

@yarnball
Copy link

I'm very keen to get this working in Sublime- has anyone had success?

@octref octref added this to the quickfix milestone Feb 13, 2019
@frankdugan3
Copy link

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 vue tag to make this work, but I'd be happy to add that to my components. I already do it for my GraphQL files.

@octref octref removed this from the quickfix milestone May 8, 2019
@octref
Copy link
Member

octref commented May 8, 2019

@Patcher56 Would you be interested in taking this issue?

@octref octref removed the upstream label May 8, 2019
@p-kuen
Copy link
Contributor

p-kuen commented Jun 6, 2019

I'm very busy atm but I am very interested. If I have more time, I will do that for sure!

@arpadgabor
Copy link

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.

@zerodayace
Copy link

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.
In this window you have syntax highlighting and autocompletion.

Remarks: I'm not the author of this extension nor affiliated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests