@astropub/code
Advanced tools
Comparing version
@@ -5,3 +5,3 @@ { | ||
"description": "A lightweight Astro component for syntax highlighting and rendering beautifully formatted code blocks.", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"type": "module", | ||
@@ -8,0 +8,0 @@ "license": "MIT-0", |
@@ -22,11 +22,11 @@ import { Prism, type Token } from "./prism.ts" | ||
Prism.languages.jsx = Prism.languages.extend('markup', typescript); | ||
Prism.languages.jsx.tag.pattern = re( | ||
Prism.languages.tsx = Prism.languages.extend('markup', typescript); | ||
Prism.languages.tsx.tag.pattern = re( | ||
/<\/?(?:[\w.:-]+(?:<S>+(?:[\w.:$-]+(?:=(?:"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*'|[^\s{'"/>=]+|<BRACES>))?|<SPREAD>))*<S>*\/?)?>/.source | ||
); | ||
Prism.languages.jsx.tag.inside.tag.pattern = /^<\/?[^\s>\/]*/; | ||
Prism.languages.jsx.tag.inside['attr-value'].pattern = /=(?!\{)(?:"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*'|[^\s'">]+)/; | ||
Prism.languages.jsx.tag.inside.tag.inside['class-name'] = /^[A-Z]\w*(?:\.[A-Z]\w*)*$/; | ||
Prism.languages.jsx.tag.inside.comment = typescript.comment; | ||
Prism.languages.tsx.tag.inside.tag.pattern = /^<\/?[^\s>\/]*/; | ||
Prism.languages.tsx.tag.inside['attr-value'].pattern = /=(?!\{)(?:"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*'|[^\s'">]+)/; | ||
Prism.languages.tsx.tag.inside.tag.inside['class-name'] = /^[A-Z]\w*(?:\.[A-Z]\w*)*$/; | ||
Prism.languages.tsx.tag.inside.comment = typescript.comment; | ||
@@ -36,5 +36,5 @@ Prism.languages.insertBefore('inside', 'attr-name', { | ||
pattern: re(/<SPREAD>/.source), | ||
inside: Prism.languages.jsx | ||
inside: Prism.languages.tsx | ||
} | ||
}, Prism.languages.jsx.tag); | ||
}, Prism.languages.tsx.tag); | ||
@@ -51,6 +51,6 @@ Prism.languages.insertBefore('inside', 'special-attr', { | ||
}, | ||
rest: Prism.languages.jsx | ||
rest: Prism.languages.tsx | ||
}, | ||
} | ||
}, Prism.languages.jsx.tag); | ||
}, Prism.languages.tsx.tag); | ||
@@ -105,3 +105,3 @@ // The following will handle plain text inside tags | ||
// Here we might have entered a JSX context inside a tag | ||
// Here we might have entered a TSX context inside a tag | ||
++openedTags[openedTags.length - 1].openedBraces; | ||
@@ -111,3 +111,3 @@ | ||
// Here we might have left a JSX context inside a tag | ||
// Here we might have left a TSX context inside a tag | ||
--openedTags[openedTags.length - 1].openedBraces; | ||
@@ -119,5 +119,6 @@ | ||
} | ||
if (notTagNorBrace || typeof token === 'string') { | ||
if (openedTags.length > 0 && openedTags[openedTags.length - 1].openedBraces === 0) { | ||
// Here we are inside a tag, and not inside a JSX context. | ||
// Here we are inside a tag, and not inside a TSX context. | ||
// That's plain text: drop any tokens matched. | ||
@@ -148,3 +149,3 @@ let plainText = stringifyToken(token); | ||
Prism.hooks.add('after-tokenize', (env) => { | ||
if (env.language !== 'jsx') { | ||
if (env.language !== 'tsx') { | ||
return; | ||
@@ -151,0 +152,0 @@ } |
61707
0