Open JC3 opened 7 years ago
The same is true for // inside backticks
To elaborate on the above comment, with a string like
let url = `http://example.com`
everything after http:
is interpreted as a comment by the syntax highlighter.
Possibly related to https://github.com/google/code-prettify/issues/217
Just a note this is affecting all current JavaScript on StackOverflow
Handling this properly will require keeping a bracket stack.
`start of string
${ // inside an interpolation
{ toString() { return 'foo' } } // None of these brackets put us back into the string
/* but this one does --> */}
now we're back in the string
${ /but not for long [}]/
} and we're back but
${
`this string is in a string ${ `me too` }`
}`;
Tagged template literals should be supported as well in order to support frameworks such as lit-element
const style = css`
/* formatted as CSS */
p {
color: blue;
}
`;
const template = html`
<!-- formatted as HTML -->
<p>Hello world</p>
<my-element
.hidden=${/* formatted as JS */ a + b > c}
></my-element>
`;
@jolleekin How would prettify know that the html and css tags correspond to those languages?
@mikesamuel It's based on the tag function. Please look at these projects
The
lang-js
highlighter (as used on Stack Exchange) does not appear to recognize backticked strings properly:Currently renders like this (when js highlighter specified):
A number of issues are shown above:
All text except placeholder expressions should be highlighted as a string (or perhaps even a unique color, Tampermonkey style) when inside backticks.
Chrome 58, Windows.