shikijs / shiki

A beautiful yet powerful syntax highlighter

Home Page:http://shiki.style/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

Only566 opened this issue · comments

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

  • I am willing to submit a PR to fix this issue
  • I am willing to submit a PR with failing tests

PR welcome :)

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).