Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MDX] Add Prism and Shiki support #4002

Merged
merged 21 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: shiki, shikiConfig, prism
  • Loading branch information
bholmesdev committed Jul 21, 2022
commit 65889fbd866a9207ed0c086df92806a92c789acf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Syntax highlighting

```astro
---
const handlesAstroSyntax = true
---

<h1>{handlesAstroSyntax}</h1>
```
67 changes: 67 additions & 0 deletions packages/integrations/mdx/test/mdx-syntax-highlighting.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import mdx from '@astrojs/mdx';

import { expect } from 'chai';
import { parseHTML } from 'linkedom';
import { loadFixture } from '../../../astro/test/test-utils.js';

const FIXTURE_ROOT = new URL('./fixtures/mdx-syntax-hightlighting/', import.meta.url);

describe('MDX syntax highlighting', () => {
describe('shiki', () => {
it('works', async () => {
const fixture = await loadFixture({
root: FIXTURE_ROOT,
markdown: {
syntaxHighlight: 'shiki',
},
integrations: [mdx()],
});
await fixture.build();

const html = await fixture.readFile('/index.html');
const { document } = parseHTML(html);

const shikiCodeBlock = document.querySelector('pre.shiki');
expect(shikiCodeBlock).to.not.be.null;
});

it('respects markdown.shikiConfig.theme', async () => {
const fixture = await loadFixture({
root: FIXTURE_ROOT,
markdown: {
syntaxHighlight: 'shiki',
shikiConfig: {
theme: 'dracula',
},
},
integrations: [mdx()],
});
await fixture.build();

const html = await fixture.readFile('/index.html');
const { document } = parseHTML(html);

const shikiCodeBlock = document.querySelector('pre.shiki.dracula');
expect(shikiCodeBlock).to.not.be.null;
});
});

describe('prism', () => {
it('works', async () => {
const fixture = await loadFixture({
root: FIXTURE_ROOT,
markdown: {
syntaxHighlight: 'prism',
},
integrations: [mdx()],
});
await fixture.build();

const html = await fixture.readFile('/index.html');
const { document } = parseHTML(html);

const prismCodeBlock = document.querySelector('pre.language-astro');
expect(prismCodeBlock).to.not.be.null;
});
});
});