forked from laptou/astro
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Shiki as an alternative to Prism (withastro#2497)
* [ci] yarn format * Added shiki to markdown-remark * Upgraded astro shiki * Added minimal example * Changed defaults to match <Code /> * Replace `shiki` with `astro` classes * Added documentation * Updated Astro code to use new `codeToHtml` * Added changesets * Added basic test * Updated tests a bit Co-authored-by: JuanM04 <JuanM04@users.noreply.github.com>
- Loading branch information
Showing
6 changed files
with
107 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { expect } from 'chai'; | ||
import cheerio from 'cheerio'; | ||
import { loadFixture } from './test-utils.js'; | ||
import markdownRemark from '@astrojs/markdown-remark'; | ||
|
||
describe('Astro Markdown Shiki', () => { | ||
let fixture; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ | ||
projectRoot: './fixtures/astro-markdown-shiki/', | ||
markdownOptions: { | ||
render: [ | ||
markdownRemark, | ||
{ | ||
syntaxHighlight: 'shiki', | ||
shikiTheme: 'github-light', | ||
}, | ||
], | ||
}, | ||
buildOptions: { | ||
sitemap: false, | ||
}, | ||
}); | ||
await fixture.build(); | ||
}); | ||
|
||
it('Can render markdown with shiki', async () => { | ||
const html = await fixture.readFile('/index.html'); | ||
const $ = cheerio.load(html); | ||
|
||
// There should be no HTML from Prism | ||
expect($('.token')).to.have.lengthOf(0); | ||
|
||
expect($('pre')).to.have.lengthOf(1); | ||
expect($('pre').hasClass('astro-code')).to.equal(true); | ||
expect($('pre').attr().style).to.equal('background-color: #ffffff'); | ||
}); | ||
|
||
it('Can render Astro <Markdown> with shiki', async () => { | ||
const html = await fixture.readFile('/astro/index.html'); | ||
const $ = cheerio.load(html); | ||
|
||
// There should be no HTML from Prism | ||
expect($('.token')).to.have.lengthOf(0); | ||
|
||
expect($('pre')).to.have.lengthOf(2); | ||
|
||
expect($('span.line')).to.have.lengthOf(2); | ||
expect($('span.line').get(0).children).to.have.lengthOf(1); | ||
expect($('span.line').get(1).children).to.have.lengthOf(5); | ||
}); | ||
}); |
10 changes: 10 additions & 0 deletions
10
test/fixtures/astro-markdown-shiki/src/layouts/content.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<html> | ||
<head> | ||
<!-- Head Stuff --> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<slot></slot> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
import { Markdown } from 'astro/components'; | ||
import Layout from '../layouts/content.astro'; | ||
--- | ||
|
||
<Layout> | ||
<Markdown> | ||
# Hello world | ||
|
||
``` | ||
plaintext | ||
``` | ||
|
||
```js | ||
console.log('JavaScript') | ||
``` | ||
</Markdown> | ||
</Layout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
layout: ../layouts/content.astro | ||
--- | ||
|
||
# Hello world | ||
|
||
```yaml | ||
apiVersion: v3 | ||
kind: Pod | ||
metadata: | ||
name: rss-site | ||
labels: | ||
app: web | ||
spec: | ||
containers: | ||
- name: front-end | ||
image: nginx | ||
ports: | ||
- containerPort: 80 | ||
- name: rss-reader | ||
image: nickchase/rss-php-nginx:v1 | ||
ports: | ||
- containerPort: 88 | ||
``` |