import { parseHTML } from 'linkedom'; import { expect } from 'chai'; import Markdoc from '@markdoc/markdoc'; import shiki from '../dist/extensions/shiki.js'; import prism from '../dist/extensions/prism.js'; import { setupConfig } from '../dist/runtime.js'; import { isHTMLString } from 'astro/runtime/server/index.js'; const entry = ` \`\`\`ts const highlighting = true; \`\`\` \`\`\`css .highlighting { color: red; } \`\`\` `; describe('Markdoc - syntax highlighting', () => { describe('shiki', () => { it('transforms with defaults', async () => { const ast = Markdoc.parse(entry); const content = Markdoc.transform(ast, await getConfigExtendingShiki()); expect(content.children).to.have.lengthOf(2); for (const codeBlock of content.children) { expect(isHTMLString(codeBlock)).to.be.true; const pre = parsePreTag(codeBlock); expect(pre.classList).to.include('astro-code'); expect(pre.classList).to.include('github-dark'); } }); it('transforms with `theme` property', async () => { const ast = Markdoc.parse(entry); const content = Markdoc.transform( ast, await getConfigExtendingShiki({ theme: 'dracula', }) ); expect(content.children).to.have.lengthOf(2); for (const codeBlock of content.children) { expect(isHTMLString(codeBlock)).to.be.true; const pre = parsePreTag(codeBlock); expect(pre.classList).to.include('astro-code'); expect(pre.classList).to.include('dracula'); } }); it('transforms with `wrap` property', async () => { const ast = Markdoc.parse(entry); const content = Markdoc.transform( ast, await getConfigExtendingShiki({ wrap: true, }) ); expect(content.children).to.have.lengthOf(2); for (const codeBlock of content.children) { expect(isHTMLString(codeBlock)).to.be.true; const pre = parsePreTag(codeBlock); expect(pre.getAttribute('style')).to.include('white-space: pre-wrap'); expect(pre.getAttribute('style')).to.include('word-wrap: break-word'); } }); }); describe('prism', () => { it('transforms', async () => { const ast = Markdoc.parse(entry); const config = await setupConfig({ extends: [prism()], }); const content = Markdoc.transform(ast, config); expect(content.children).to.have.lengthOf(2); const [tsBlock, cssBlock] = content.children; expect(isHTMLString(tsBlock)).to.be.true; expect(isHTMLString(cssBlock)).to.be.true; const preTs = parsePreTag(tsBlock); expect(preTs.classList).to.include('language-ts'); const preCss = parsePreTag(cssBlock); expect(preCss.classList).to.include('language-css'); }); }); }); /** * @param {import('astro').ShikiConfig} config * @returns {import('../src/config.js').AstroMarkdocConfig} */ async function getConfigExtendingShiki(config) { return await setupConfig({ extends: [shiki(config)], }); } /** * @param {string} html * @returns {HTMLPreElement} */ function parsePreTag(html) { const { document } = parseHTML(html); const pre = document.querySelector('pre'); expect(pre).to.exist; return pre; } ion> Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
path: root/docs/guides/ecosystem/react.md (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2023-10-09fix(AbortSignal/fetch) fix AbortSignal.timeout, fetch lock behavior and fetch...Gravatar Ciro Spaciari 29-61/+303
2023-10-09Fix npm tag for canary bun-types, againGravatar Ashcon Partovi 2-56/+10
2023-10-09Add Fedora build instructions to development.md (#6359)Gravatar otterDeveloper 1-0/+10
2023-10-09added commands (#6314)Gravatar babar 1-1/+2
2023-10-09Update README.md (#6291)Gravatar TPLJ 1-1/+1
2023-10-09docs: fixing a couple typos (#6331)Gravatar Michael Di Prisco 2-2/+2
2023-10-09fix: support uint8 exit code range (#6303)Gravatar Liz 2-2/+11
2023-10-09Fix array variables preview in debugger (#6379)Gravatar 2hu 1-1/+4
2023-10-07feat(KeyObject) (#5940)Gravatar Ciro Spaciari 106-67/+9342
2023-10-07Exclude more filesGravatar Jarred Sumner 1-1/+1
2023-10-07Exclude more filesGravatar Jarred Sumner 1-1/+2
2023-10-07Update settings.jsonGravatar Jarred Sumner 1-1/+2
2023-10-07Update settings.jsonGravatar Jarred Sumner 1-2/+3
2023-10-06fix a couple install testsGravatar Dylan Conway 1-8/+8
2023-10-06formatGravatar Dylan Conway 1-1/+2
2023-10-06Fix memory leak in fetch() (#6350)Gravatar Jarred Sumner 1-2/+0
2023-10-06[types] allow onLoad plugin callbacks to return undefined (#6346)Gravatar Silver 1-1/+1
2023-10-06docs: `file.stream()` is not a promise (#6337)Gravatar Paul Nodet 1-1/+1