aboutsummaryrefslogtreecommitdiff
path: root/packages/markdown/remark/test/shiki.test.js
diff options
context:
space:
mode:
Diffstat (limited to 'packages/markdown/remark/test/shiki.test.js')
-rw-r--r--packages/markdown/remark/test/shiki.test.js26
1 files changed, 17 insertions, 9 deletions
diff --git a/packages/markdown/remark/test/shiki.test.js b/packages/markdown/remark/test/shiki.test.js
index ca17ab1d8..45582d752 100644
--- a/packages/markdown/remark/test/shiki.test.js
+++ b/packages/markdown/remark/test/shiki.test.js
@@ -33,16 +33,25 @@ describe('shiki syntax highlighting', () => {
it('createShikiHighlighter works', async () => {
const highlighter = await createShikiHighlighter();
- const html = await highlighter.highlight('const foo = "bar";', 'js');
+ const html = await highlighter.codeToHtml('const foo = "bar";', 'js');
assert.match(html, /astro-code github-dark/);
assert.match(html, /background-color:#24292e;color:#e1e4e8;/);
});
+ it('createShikiHighlighter works with codeToHast', async () => {
+ const highlighter = await createShikiHighlighter();
+
+ const hast = await highlighter.codeToHast('const foo = "bar";', 'js');
+
+ assert.match(hast.children[0].properties.class, /astro-code github-dark/);
+ assert.match(hast.children[0].properties.style, /background-color:#24292e;color:#e1e4e8;/);
+ });
+
it('diff +/- text has user-select: none', async () => {
const highlighter = await createShikiHighlighter();
- const html = await highlighter.highlight(
+ const html = await highlighter.codeToHtml(
`\
- const foo = "bar";
+ const foo = "world";`,
@@ -57,7 +66,7 @@ describe('shiki syntax highlighting', () => {
it('renders attributes', async () => {
const highlighter = await createShikiHighlighter();
- const html = await highlighter.highlight(`foo`, 'js', {
+ const html = await highlighter.codeToHtml(`foo`, 'js', {
attributes: { 'data-foo': 'bar', autofocus: true },
});
@@ -66,7 +75,10 @@ describe('shiki syntax highlighting', () => {
});
it('supports transformers that reads meta', async () => {
- const highlighter = await createShikiHighlighter({
+ const highlighter = await createShikiHighlighter();
+
+ const html = await highlighter.codeToHtml(`foo`, 'js', {
+ meta: '{1,3-4}',
transformers: [
{
pre(node) {
@@ -79,10 +91,6 @@ describe('shiki syntax highlighting', () => {
],
});
- const html = await highlighter.highlight(`foo`, 'js', {
- meta: '{1,3-4}',
- });
-
assert.match(html, /data-test="\{1,3-4\}"/);
});
@@ -109,7 +117,7 @@ describe('shiki syntax highlighting', () => {
},
});
- const html = await highlighter.highlight(`let test = "some string"`, 'cjs', {
+ const html = await highlighter.codeToHtml(`let test = "some string"`, 'cjs', {
attributes: { 'data-foo': 'bar', autofocus: true },
});