Skip to content

Commit

Permalink
Support style tags
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Jun 24, 2023
1 parent 4ee1755 commit c5a9256
Show file tree
Hide file tree
Showing 8 changed files with 277 additions and 56 deletions.
5 changes: 5 additions & 0 deletions .changeset/grumpy-timers-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'highlightjs-glimmer': minor
---

Support <style> tags
54 changes: 54 additions & 0 deletions highlightjs-glimmer/dist/glimmer.cjs.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,61 @@ function glimmer(hljs) {
}
];
STRING.variants.forEach((variant) => variant.contains.push(...MUSTACHE_EXPRESSION));
const XML_IDENT_RE = /[\p{L}0-9._:-]+/u;
const TAG_INTERNALS = {
endsWithParent: true,
illegal: /</,
relevance: 0,
contains: [
{
className: "attr",
begin: XML_IDENT_RE,
relevance: 0
},
{
begin: /=\s*/,
relevance: 0,
contains: [
{
className: "string",
endsParent: true,
variants: [
{
begin: /"/,
end: /"/,
contains: [XML_ENTITIES]
},
{
begin: /'/,
end: /'/,
contains: [XML_ENTITIES]
},
{ begin: /[^\s"'=<>`]+/ }
]
}
]
}
]
};
const STYLE_TAG = {
className: "tag",
/*
The lookahead pattern (?=...) ensures that 'begin' only matches
'<style' as a single word, followed by a whitespace or an
ending bracket.
*/
begin: /<style(?=\s|>)/,
end: />/,
keywords: { name: "style" },
contains: [TAG_INTERNALS],
starts: {
end: /<\/style>/,
returnEnd: true,
subLanguage: ["css", "xml"]
}
};
const ANGLE_BRACKET_BLOCK = [
STYLE_TAG,
{
className: "tag",
begin: regex.concat(
Expand Down
2 changes: 1 addition & 1 deletion highlightjs-glimmer/dist/glimmer.esm.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion highlightjs-glimmer/dist/glimmer.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions highlightjs-glimmer/src/glimmer.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,63 @@ export default function glimmer(hljs) {

STRING.variants.forEach((variant) => variant.contains.push(...MUSTACHE_EXPRESSION));

const XML_IDENT_RE = /[\p{L}0-9._:-]+/u;
const TAG_INTERNALS = {
endsWithParent: true,
illegal: /</,
relevance: 0,
contains: [
{
className: 'attr',
begin: XML_IDENT_RE,
relevance: 0,
},
{
begin: /=\s*/,
relevance: 0,
contains: [
{
className: 'string',
endsParent: true,
variants: [
{
begin: /"/,
end: /"/,
contains: [XML_ENTITIES],
},
{
begin: /'/,
end: /'/,
contains: [XML_ENTITIES],
},
{ begin: /[^\s"'=<>`]+/ },
],
},
],
},
],
};

const STYLE_TAG = {
className: 'tag',
/*
The lookahead pattern (?=...) ensures that 'begin' only matches
'<style' as a single word, followed by a whitespace or an
ending bracket.
*/
begin: /<style(?=\s|>)/,
end: />/,
keywords: { name: 'style' },
contains: [TAG_INTERNALS],
starts: {
end: /<\/style>/,
returnEnd: true,
subLanguage: ['css', 'xml'],
},
};

const ANGLE_BRACKET_BLOCK = [
STYLE_TAG,
{
className: 'tag',
begin: regex.concat(
Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<!-- Highlight.JS does not ship ES Modules to CDNs... yet! -->
<script src="https://cdn.jsdelivr.net/npm/@highlightjs/[email protected]/highlight.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@highlightjs/[email protected]/languages/javascript.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@highlightjs/[email protected]/languages/css.min.js"></script>

<!-- Hybrid Theme! -->
<link
Expand Down
Loading

0 comments on commit c5a9256

Please sign in to comment.