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

Shiki's built-in ANSI language doesn't work #10539

Closed
1 task done
imkunet opened this issue Mar 23, 2024 · 1 comment
Closed
1 task done

Shiki's built-in ANSI language doesn't work #10539

imkunet opened this issue Mar 23, 2024 · 1 comment
Labels
needs triage Issue needs to be triaged

Comments

@imkunet
Copy link
Contributor

imkunet commented Mar 23, 2024

Astro Info

Astro                    v4.5.9
Node                     v20.3.0
System                   Linux (x64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             @astrojs/tailwind
                         @astrojs/mdx
                         @astrojs/sitemap

Describe the Bug

Shiki's built-in ANSI language isn't correctly rendering.

When attempting to render a code block with the ansi language, the following console log can be observed:

[Shiki] The language "ansi" doesn't exist, falling back to "plaintext".

As a side note, out of the hard coded Shiki languages: ansi, plaintext, txt, text, and plain, only plaintext works. (The others fail with a similar error message as above)

Likely culprit

While I cannot test this directly (due to the lack of knowledge about testing and developing on this particular project), there is this line which I have found in the code which I believe to be a likely culprit.

if (lang !== 'plaintext' && !loadedLanguages.includes(lang)) {

What's the expected result?

What should happen is the ANSI correctly renders with colors. A working example to contrast the Stackblitz link (with the same content used as in the Stackblitz link) can be found here, on Shiki's documentation.

Likely fix

My hunch is that (with again, no way to test or prove it) that the above code snippet should be using the following function inside Shiki itself instead of just checking the plaintext case:

https://github.com/shikijs/shiki/blob/ec2bffae1c5cf9ab9e3fcc12a8ed1a5143e99707/packages/core/src/utils.ts#L41

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-bse4te?file=src%2Fpages%2Findex.mdx

Participation

  • I am willing to submit a pull request for this issue.
    EDIT: After figuring it out, I think the fix works! Going to PR now.
@matthewp
Copy link
Contributor

Thanks! And thanks for the PR too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

2 participants