Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// NOTE: This highlights template-strings as strings of CSS
Prism.languages.insertBefore('jsx', 'template-string', {
'styled-template-string': {
pattern: /(styled(\.\w+|\([^\)]*\))(\.\w+(\([^\)]*\))*)*|css|injectGlobal|createGlobalStyle|keyframes|\.extend|\.withComponent)`(?:\$\{[^}]+\}|\\\\|\\?[^\\])*?`/,
lookbehind: true,
greedy: true,
inside: {
interpolation: {
pattern: /\$\{[^}]+\}/,
inside: {
'interpolation-punctuation': {
pattern: /^\$\{|\}$/,
alias: 'punctuation',
},
rest: languages.jsx,
},
},
string: {
pattern: /[^$;]+/,
inside: languages.css,
alias: 'language-css',
},
},
},
});
export { languages };
_highlight = code => {
if (this.props.path.endsWith('.js')) {
return highlight(code, languages.jsx);
} else if (this.props.path.endsWith('.json')) {
return highlight(code, languages.json);
} else if (this.props.path.endsWith('.md')) {
return highlight(code, languages.markdown);
}
return escape(code);
};
_highlight = (code: string) => {
if (this.props.path.endsWith('.ts') || this.props.path.endsWith('.tsx')) {
return highlight(code, languages.ts);
} else if (this.props.path.endsWith('.js')) {
return highlight(code, languages.jsx);
} else if (this.props.path.endsWith('.json')) {
return highlight(code, languages.json);
} else if (this.props.path.endsWith('.md')) {
return highlight(code, languages.markdown);
}
return escape(code);
};
highlight: (code, lang) => {
const grammar = lang === 'js' ? languages.jsx : languages[lang];
return grammar ? highlight(code, grammar) : escape(code);
},
});
highlight={code => highlight(code, languages.jsx)}
padding={10}