Hightlighting doesn't work with nested template string and with css helper.
See original GitHub issue- Doesn’t highlight code if I use a tagged template inside the template string (see middle image) (#254 ).
- The above problem (1) can be solved by using css helper before the tagged template.
- The above solution (2) cause highlight not to work further down (see right screenshot)
(The solution does work well on codesandbox but not in vscode - see here)
Screenshot
Code for left & middle screenshots:
const box1 = styled.div`
display: grid;
grid-template-columns: repeat(9, 1fr);
grid-column: 6/11;
color: ${myColor};
color: red;
${
setMediaQuery('big')`
display: grid;
color: ${myColor};
color: red;
grid-column: 6/11;
grid-template-columns: repeat(9, 1fr);
`
}
${
setMediaQuery('medium')`
display: grid;
grid-template-columns: repeat(9, 1fr);
grid-column: 6/11;
color: red;
`
}
`;
const box2 = styled.div`
display: grid;
grid-template-columns: repeat(9, 1fr);
grid-column: 6/11;
color: ${myColor};
`;
export default {
box1,
box2,
};
Code for the right screenshot:
import styled, { css } from 'styled-components';
const myColor = '#333';
export const setMediaQuery = (breakpoint) => {
switch (breakpoint) {
case 'small':
return (style) => `@media (max-width: 800px) { ${style} }`;
case 'medium':
return (style) => `@media (min-width: 801px) (max-width: 1200) { ${style} }`;
default:
return (style) => `@media (min-width: 1201px) { ${style} }`;
}
};
const box1 = styled.div`
display: grid;
grid-template-columns: repeat(9, 1fr);
grid-column: 6/11;
color: ${myColor};
color: red;
${
setMediaQuery('big')(css`
display: grid;
color: ${myColor};
color: red;
grid-column: 6/11;
grid-template-columns: repeat(9, 1fr);
`)
}
${
setMediaQuery('medium')(css`
display: grid;
grid-template-columns: repeat(9, 1fr);
grid-column: 6/11;
color: red;
`)
}
`;
const box2 = styled.div`
display: grid;
grid-template-columns: repeat(9, 1fr);
grid-column: 6/11;
color: ${myColor};
`;
export default {
box1,
box2,
};
- OS: Win 10
- VSCode Version: 1.52.0
- Extension Version 1.4.1
Thanks!
Issue Analytics
- State:
- Created 3 years ago
- Reactions:7
- Comments:10
Top Results From Across the Web
Highlighting nested Markdown, and within JavaScript template ...
I'm curious if there is a better way to do this. CodeMirror 6 handles it quite well, though, so mostly I'd just like...
Read more >VSCODE Javascript template string become white and lost ...
In some cases, apparently random, when using JavaScript string templates, the text editor loses becomes white, with bold text and makes editing ...
Read more >Syntax Highlight Guide | Visual Studio Code Extension API
A guide to syntax highlighting. ... Tokens are used for syntax highlighting, but also to classify the source code into areas of comments,...
Read more >Template literals (Template strings) - JavaScript | MDN
In certain cases, nesting a template is the easiest (and perhaps more readable) way to have configurable strings. Within a backtick-delimited ...
Read more >Pandoc User's Guide
It is possible to supply a custom User-Agent string or other header when requesting a ... epub.css , templates ) will override pandoc's...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @ndeviant,
See https://github.com/styled-components/vscode-styled-components/issues/304 or this codepen.
TLDR: You can pass your styles to the built-in css helper:
Thanks @stg101