shikijs / shiki

A beautiful yet powerful syntax highlighter
http://shiki.style/
MIT License
9.19k stars 330 forks source link

@shikijs/markdown-it: code block is wrong when entering a non-existent language #687

Closed Only566 closed 1 month ago

Only566 commented 1 month ago

Validations

Describe the bug

Code block is wrong when entering a non-existent language, even if the input is not complete, an error will be reported. image image

Allowing configuration of a default language during initialization may be a good solution.

MarkdownItPluginShiki({
  defaultLang: 'text'
})

Reproduction

-

Contributes

antfu commented 1 month ago

PR welcome :)

rglover commented 1 month ago

This can be resolved if you add a fallbackLanguage to the options like so:

md.use(await Shiki({
  fallbackLanguage: 'javascript',
  defaultLanguage: 'javascript',
  themes: {
    light: 'slack-ochin',
  }
}));

Just tested against latest v1.6.2 release and can confirm it falls back as expected when you have non-existent language (or a typo in the language name).