summaryrefslogtreecommitdiff
path: root/packages/integrations/mdx/test/mdx-syntax-highlighting.test.js
diff options
context:
space:
mode:
authorGravatar Bjorn Lu <bjornlu.dev@gmail.com> 2022-11-09 21:32:13 +0800
committerGravatar GitHub <noreply@github.com> 2022-11-09 08:32:13 -0500
commitdca762cf734a657d8f126fd6958892b6163a4f67 (patch)
tree25598ee01bdf771106d05186a05432a2b0f8b43d /packages/integrations/mdx/test/mdx-syntax-highlighting.test.js
parentdc00ca464865feccd3760b54e0ccc58dbc1e804d (diff)
downloadastro-dca762cf734a657d8f126fd6958892b6163a4f67.tar.gz
astro-dca762cf734a657d8f126fd6958892b6163a4f67.tar.zst
astro-dca762cf734a657d8f126fd6958892b6163a4f67.zip
Preserve code element node meta for rehype syntax highlighters (#5335)
Diffstat (limited to 'packages/integrations/mdx/test/mdx-syntax-highlighting.test.js')
-rw-r--r--packages/integrations/mdx/test/mdx-syntax-highlighting.test.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/packages/integrations/mdx/test/mdx-syntax-highlighting.test.js b/packages/integrations/mdx/test/mdx-syntax-highlighting.test.js
index 70da75357..6203ed82c 100644
--- a/packages/integrations/mdx/test/mdx-syntax-highlighting.test.js
+++ b/packages/integrations/mdx/test/mdx-syntax-highlighting.test.js
@@ -4,6 +4,7 @@ import { expect } from 'chai';
import { parseHTML } from 'linkedom';
import { loadFixture } from '../../../astro/test/test-utils.js';
import shikiTwoslash from 'remark-shiki-twoslash';
+import rehypePrettyCode from 'rehype-pretty-code';
const FIXTURE_ROOT = new URL('./fixtures/mdx-syntax-hightlighting/', import.meta.url);
@@ -88,4 +89,31 @@ describe('MDX syntax highlighting', () => {
const twoslashCodeBlock = document.querySelector('pre.shiki');
expect(twoslashCodeBlock).to.not.be.null;
});
+
+ it('supports custom highlighter - rehype-pretty-code', async () => {
+ const fixture = await loadFixture({
+ root: FIXTURE_ROOT,
+ markdown: {
+ syntaxHighlight: false,
+ },
+ integrations: [
+ mdx({
+ rehypePlugins: [
+ [
+ rehypePrettyCode,
+ {
+ onVisitHighlightedLine(node) {
+ node.properties.style = 'background-color:#000000';
+ },
+ },
+ ],
+ ],
+ }),
+ ],
+ });
+ await fixture.build();
+
+ const html = await fixture.readFile('/index.html');
+ expect(html).to.include('style="background-color:#000000"')
+ });
});