-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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(markdown): add support for shiki
option langAlias
#12039
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: a6a6995 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
This PR is blocked because it contains a minor
changeset. A reviewer will merge this at the next release if approved.
langAlias
shiki
option langAlias
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.
This looks cool, @ematipico ! I checked out the original feature documentation, and made a suggestion below for your consideration!
.changeset/dirty-socks-sip.md
Outdated
Adds a configuration called https://shiki.style/guide/load-lang#custom-language-aliases, that allows a non-supported code language to a known language. | ||
|
||
The below example will tell shiki to highlight the code blocks `cjs` using the `javascript` syntax highlighting. |
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.
Adds a configuration called https://shiki.style/guide/load-lang#custom-language-aliases, that allows a non-supported code language to a known language. | |
The below example will tell shiki to highlight the code blocks `cjs` using the `javascript` syntax highlighting. | |
Adds a new Shiki configuration option `langAlias` to use [Shiki's `langAlias` option](https://shiki.style/guide/load-lang#custom-language-aliases). This allows you to define custom aliases for [Shiki's bundled language IDs](https://shiki.style/languages#bundled-languages) (such as the built-in `js` for `javascript`) for Markdown code blocks. | |
This can be used to map a non-supported code language to a known language, allowing you to indicate the exact language in your source code while using appropriate highlighting. | |
The example below configures any code blocks using the language alias `cjs` to use `javascript` syntax highlighting. |
Maybe something like this? I took a look at the original feature, and their example seems a little more general purpose than only using a language that doesn't have a supported code. It seems you could create an alias for any reason, using anything, so I think describing this as one particular use case vs. "what this thing is for" frames it as being able to be used in other ways, too.
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.
@sarah11918 I updated the changeset based on #12039 (comment), can you provide a new suggestion?
.changeset/dirty-socks-sip.md
Outdated
|
||
Adds a configuration called https://shiki.style/guide/load-lang#custom-language-aliases, that allows a non-supported code language to a known language. | ||
|
||
This option requires `langs` to be defined with the correct values. The option will tell shiki which language to load when mapping the alias. |
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.
Digging deeper into this now, it seems like a Shiki bug that requires you to specify the langs
beforehand for aliases. It might be good to followup upstream 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.
Well, the docs show that javascript
is in the array
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.
I don't think you have to. You can specify the langs upfront so that you can syntax highlight the code synchronously, but Astro doesn't do that and will always load the langs dynamically, so in practice the langs
field is only for additional custom languages.
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.
Just noting that I came to peek in on this PR and I'm not sure whether this behaviour has been confirmed yet, so I'll wait to review!
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.
Is good for docs review now 👍
Co-authored-by: Bjorn Lu <[email protected]>
Actually it's our own bug 😅 I went ahead and push a commit to fix it. The idea is to use the aliased lang for |
Changes
Closes withastro/roadmap#954
This PR adds support for
langAlias
Testing
I added new tests
Docs
withastro/docs#9453