withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
46.65k stars 2.48k forks source link

🐛 BUG: Shiki missing language registration should not fail markdown processing #3881

Closed crutchcorn closed 2 years ago

crutchcorn commented 2 years ago

What version of astro are you using?

1.0.0-beta.65

Are you using an SSR adapter? If so, which one?

None

What package manager are you using?

npm

What operating system are you using?

Windows

Describe the Bug

When using Shiki, the following Markdown will fail:

```nasm
100001 # addu

With the following error:

error Failed to parse Markdown file "C:\Users\crutchcorn\git\Astro\unicorn-astro\content\blog\how-computers-speak\index.md": No language registration for nasm at getGrammar (C:\Users\crutchcorn\git\Astro\unicorn-astro\node_modules\shiki\dist\index.js:2175:19) at codeToThemedTokens (C:\Users\crutchcorn\git\Astro\unicorn-astro\node_modules\shiki\dist\index.js:2184:30) at Object.codeToHtml (C:\Users\crutchcorn\git\Astro\unicorn-astro\node_modules\shiki\dist\index.js:2201:24) at file:///C:/Users/crutchcorn/git/Astro/unicorn-astro/node_modules/@astrojs/markdown-remark/dist/remark-shiki.js:17:30 at overload (file:///C:/Users/crutchcorn/git/Astro/unicorn-astro/node_modules/unist-util-visit/index.js:50:16) at node (code) (file:///C:/Users/crutchcorn/git/Astro/unicorn-astro/node_modules/unist-util-visit-parents/index.js:104:31) at node (root) (file:///C:/Users/crutchcorn/git/Astro/unicorn-astro/node_modules/unist-util-visit-parents/index.js:121:79) at visitParents (file:///C:/Users/crutchcorn/git/Astro/unicorn-astro/node_modules/unist-util-visit-parents/index.js:61:30) at visit (file:///C:/Users/crutchcorn/git/Astro/unicorn-astro/node_modules/unist-util-visit/index.js:42:7) at file:///C:/Users/crutchcorn/git/Astro/unicorn-astro/node_modules/@astrojs/markdown-remark/dist/remark-shiki.js:16:5 (x2)



As @Princesseuh pointed out on Discord, it seems like this behavior is thrown from Shiki itself

https://github.com/shikijs/shiki/blob/b0cade2f48f3d6e5c0897c81d0dd06c81f5916ab/packages/shiki/src/highlighter.ts#L108

But Shiki's official `remark` plugin seems to catch this error:

https://github.com/shikijs/twoslash/blob/main/packages/remark-shiki-twoslash/src/index.ts#L167-L172

I think this should be the same behavior we seek to implement in Astro. Otherwise, it enables other's content to break a build, which seems to be too harsh of an action

### Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-nxlpqd?file=src%2Fpages%2Fposts%2Findex.md&on=stackblitz

### Participation

- [X] I am willing to submit a pull request for this issue.
matthewp commented 2 years ago

What behavior are you expecting to happen here? I can't tell from the linked code.

Princesseuh commented 2 years ago

What I'd personally expect is the following:

crutchcorn commented 2 years ago

100% agree with @Princesseuh in her expected behavior. This is what the ""upstream"" remark-shiki-twoslash plugin does.