-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(shiki): add support for `langAlias` * chore: apply feedback * Update packages/markdown/remark/src/types.ts Co-authored-by: Bjorn Lu <[email protected]> * fix build * Fix bug * Apply suggestions from code review Co-authored-by: Sarah Rainsberger <[email protected]> * Update .changeset/dirty-socks-sip.md --------- Co-authored-by: Bjorn Lu <[email protected]> Co-authored-by: Sarah Rainsberger <[email protected]>
- Loading branch information
1 parent
3ac2263
commit 710a1a1
Showing
6 changed files
with
78 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
'@astrojs/markdown-remark': minor | ||
'astro': minor | ||
--- | ||
|
||
Adds a `markdown.shikiConfig.langAlias` option that allows [aliasing a non-supported code language to a known language](https://shiki.style/guide/load-lang#custom-language-aliases). This is useful when the language of your code samples is not [a built-in Shiki language](https://shiki.style/languages), but you want your Markdown source to contain an accurate language while also displaying syntax highlighting. | ||
|
||
The following example configures Shiki to highlight `cjs` code blocks using the `javascript` syntax highlighter: | ||
|
||
```js | ||
import { defineConfig } from 'astro/config'; | ||
|
||
export default defineConfig({ | ||
markdown: { | ||
shikiConfig: { | ||
langAlias: { | ||
cjs: 'javascript', | ||
}, | ||
}, | ||
}, | ||
}); | ||
``` | ||
|
||
Then in your Markdown, you can use the alias as the language for a code block for syntax highlighting: | ||
|
||
````md | ||
```cjs | ||
'use strict'; | ||
|
||
function commonJs() { | ||
return 'I am a commonjs file'; | ||
} | ||
``` | ||
```` |
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