-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
feat: Added the ability to add custom themes/languages to Shiki #2518
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
d295815
Replaced `shikiTheme` with `shikiConfig`
JuanM04 f703715
Code.astro now accepts custom themes/langs
JuanM04 5874e38
Updated docs
JuanM04 273fbeb
Updated tests
JuanM04 948de06
Fixed language loading
JuanM04 415e403
Added customization examples
JuanM04 27be244
Updated documentation
JuanM04 030cb64
Added more tests
JuanM04 d2677f0
Changelogs
JuanM04 5ab34b8
Changed some spaces to tabs
JuanM04 0ded936
Merge branch 'main' into shiki-config
JuanM04 d318359
Fixed typo in changesets
JuanM04 63972e4
Moved tests fixtures
JuanM04 993e988
Rolled back changes to with-markdown-shiki
JuanM04 ef1873e
Removed lang example in docs
JuanM04 ffbe290
Merge branch 'main' into shiki-config
JuanM04 034f974
Optimized Code component
JuanM04 bb1fa19
Try to fix windows errors
JuanM04 af8e6c8
Merge branch 'main' into shiki-config
JuanM04 321a468
Try to see if this new tests work
JuanM04 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'astro': patch | ||
'@astrojs/markdown-remark': patch | ||
--- | ||
|
||
Added the ability to use custom themes and langs with Shiki (`<Code />` and `@astrojs/markdown-remark`) |
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,5 @@ | ||
--- | ||
'@astrojs/markdown-remark': patch | ||
--- | ||
|
||
Added `wrap` to Shiki config |
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
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 |
---|---|---|
@@ -1,53 +1,206 @@ | ||
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(); | ||
describe('Render shiki', () => { | ||
let fixture; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ projectRoot: './fixtures/astro-markdown-shiki/normal/' }); | ||
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: #0d1117; overflow-x: auto;'); | ||
}); | ||
|
||
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); | ||
}); | ||
}); | ||
|
||
it('Can render markdown with shiki', async () => { | ||
const html = await fixture.readFile('/index.html'); | ||
const $ = cheerio.load(html); | ||
describe('Themes', () => { | ||
describe('Integrated theme', async () => { | ||
let fixture; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ projectRoot: './fixtures/astro-markdown-shiki/themes-integrated/' }); | ||
await fixture.build(); | ||
}); | ||
|
||
it('Markdown file', async () => { | ||
const html = await fixture.readFile('/index.html'); | ||
const $ = cheerio.load(html); | ||
|
||
expect($('pre')).to.have.lengthOf(1); | ||
expect($('pre').hasClass('astro-code')).to.equal(true); | ||
expect($('pre').attr().style).to.equal('background-color: #ffffff; overflow-x: auto;'); | ||
}); | ||
|
||
// There should be no HTML from Prism | ||
expect($('.token')).to.have.lengthOf(0); | ||
it('<Markdown /> component', async () => { | ||
const html = await fixture.readFile('/astro/index.html'); | ||
const $ = cheerio.load(html); | ||
|
||
expect($('pre')).to.have.lengthOf(1); | ||
expect($('pre').hasClass('astro-code')).to.equal(true); | ||
expect($('pre').attr().style).to.equal('background-color: #ffffff'); | ||
expect($('pre')).to.have.lengthOf(1); | ||
expect($('pre').hasClass('astro-code')).to.equal(true); | ||
expect($('pre').attr().style).to.equal('background-color: #ffffff; overflow-x: auto;'); | ||
}); | ||
}); | ||
|
||
describe('Custom theme', async () => { | ||
let fixture; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ projectRoot: './fixtures/astro-markdown-shiki/themes-custom/' }); | ||
await fixture.build(); | ||
}); | ||
|
||
it('Markdown file', async () => { | ||
const html = await fixture.readFile('/index.html'); | ||
const $ = cheerio.load(html); | ||
|
||
expect($('pre')).to.have.lengthOf(1); | ||
expect($('pre').hasClass('astro-code')).to.equal(true); | ||
expect($('pre').attr().style).to.equal('background-color: #FDFDFE; overflow-x: auto;'); | ||
}); | ||
|
||
it('<Markdown /> component', async () => { | ||
const html = await fixture.readFile('/astro/index.html'); | ||
const $ = cheerio.load(html); | ||
|
||
expect($('pre')).to.have.lengthOf(1); | ||
expect($('pre').hasClass('astro-code')).to.equal(true); | ||
expect($('pre').attr().style).to.equal('background-color: #FDFDFE; overflow-x: auto;'); | ||
}); | ||
}); | ||
}); | ||
|
||
it('Can render Astro <Markdown> with shiki', async () => { | ||
const html = await fixture.readFile('/astro/index.html'); | ||
const $ = cheerio.load(html); | ||
describe('Custom langs', () => { | ||
let fixture; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ projectRoot: './fixtures/astro-markdown-shiki/langs/' }); | ||
await fixture.build(); | ||
}); | ||
|
||
// There should be no HTML from Prism | ||
expect($('.token')).to.have.lengthOf(0); | ||
it('Markdown file', async () => { | ||
const html = await fixture.readFile('/index.html'); | ||
const $ = cheerio.load(html); | ||
|
||
expect($('pre')).to.have.lengthOf(2); | ||
const segments = $('.line').get(6).children; | ||
expect(segments).to.have.lengthOf(3); | ||
expect(segments[0].attribs.style).to.be.equal('color: #C9D1D9'); | ||
expect(segments[1].attribs.style).to.be.equal('color: #79C0FF'); | ||
expect(segments[2].attribs.style).to.be.equal('color: #C9D1D9'); | ||
}); | ||
|
||
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); | ||
it('<Markdown /> component', async () => { | ||
const html = await fixture.readFile('/astro/index.html'); | ||
const $ = cheerio.load(html); | ||
|
||
const segments = $('.line').get(6).children; | ||
expect(segments).to.have.lengthOf(2); | ||
expect(segments[0].attribs.style).to.be.equal('color: #79C0FF'); | ||
expect(segments[1].attribs.style).to.be.equal('color: #C9D1D9'); | ||
}); | ||
}); | ||
|
||
describe('Wrap', () => { | ||
describe('wrap = true', () => { | ||
const style = 'background-color: #0d1117; overflow-x: auto; white-space: pre-wrap; word-wrap: break-word;'; | ||
let fixture; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ projectRoot: './fixtures/astro-markdown-shiki/wrap-true/' }); | ||
await fixture.build(); | ||
}); | ||
|
||
it('Markdown file', async () => { | ||
const html = await fixture.readFile('/index.html'); | ||
const $ = cheerio.load(html); | ||
|
||
expect($('pre')).to.have.lengthOf(1); | ||
expect($('pre').attr('style')).to.equal(style); | ||
}); | ||
|
||
it('<Markdown /> component', async () => { | ||
const html = await fixture.readFile('/astro/index.html'); | ||
const $ = cheerio.load(html); | ||
|
||
expect($('pre').get(0).attribs.style).to.equal(style); | ||
expect($('pre').get(1).attribs.style).to.equal(style); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('wrap = false', () => { | ||
const style = 'background-color: #0d1117; overflow-x: auto;'; | ||
let fixture; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ projectRoot: './fixtures/astro-markdown-shiki/wrap-false/' }); | ||
await fixture.build(); | ||
}); | ||
|
||
it('Markdown file', async () => { | ||
const html = await fixture.readFile('/index.html'); | ||
const $ = cheerio.load(html); | ||
|
||
expect($('pre')).to.have.lengthOf(1); | ||
expect($('pre').attr('style')).to.equal(style); | ||
}); | ||
|
||
it('<Markdown /> component', async () => { | ||
const html = await fixture.readFile('/astro/index.html'); | ||
const $ = cheerio.load(html); | ||
|
||
expect($('pre').get(0).attribs.style).to.equal(style); | ||
expect($('pre').get(1).attribs.style).to.equal(style); | ||
}); | ||
}); | ||
|
||
describe('wrap = null', () => { | ||
const style = 'background-color: #0d1117'; | ||
let fixture; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ projectRoot: './fixtures/astro-markdown-shiki/wrap-null/' }); | ||
await fixture.build(); | ||
}); | ||
|
||
it('Markdown file', async () => { | ||
const html = await fixture.readFile('/index.html'); | ||
const $ = cheerio.load(html); | ||
|
||
expect($('pre')).to.have.lengthOf(1); | ||
expect($('pre').attr('style')).to.equal(style); | ||
}); | ||
|
||
it('<Markdown /> component', async () => { | ||
const html = await fixture.readFile('/astro/index.html'); | ||
const $ = cheerio.load(html); | ||
|
||
expect($('pre').get(0).attribs.style).to.equal(style); | ||
expect($('pre').get(1).attribs.style).to.equal(style); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!