docsify icon indicating copy to clipboard operation
docsify copied to clipboard

Shiki syntax highlight support

Open noraj opened this issue 1 year ago • 3 comments

Feature request

Problem or desire

Prism syntax highlight is quite bad (highlight.js is bad too).

Proposal

Support Shiki.

Shiki has better syntax highlight because it uses TextMate grammar instead of shady regexp. It uses the same engine as in VS Code.

Implementation

I guess the only thing to do on doscify side, is to add a config option that allows to generate a different highlighter class prefix. That way all JS syntax highlighter could nearly be supported.

  • shiki: css class shiki
  • prism: css class language- prefix
  • highlightjs: css class hljs

https://shiki.style/guide/install#cdn-usage

noraj avatar Feb 02 '25 15:02 noraj

Hi @noraj , As per the requirement that customizing the code block class, I think it is feasible for now. You could register a customer renderer for code.

   window.$docsify = {
        markdown: {
          renderer: {
            code({ text, lang }) {
              return /* customized code block */ `<pre data-lang="${lang}" class="shiki language-${lang}"><code class="lang-${lang} language-${lang}" tabindex="0">${text}</code></pre>`;
            },
          },
        },
    }

Not quite sure whether Shiki support static css add-on styling for code hightlight, glad to see ur feedback on it!

Koooooo-7 avatar Jul 18 '25 12:07 Koooooo-7

Hello @noraj

Yes, I think so. I'm new to Docsify, and I've created a new project to try it out, but it doesn't seem to highlight anything.

AhmedAlaa4611 avatar Oct 03 '25 12:10 AhmedAlaa4611

it uses TextMate grammar instead of shady regexp

@noraj TextMate grammars are regexp based?

RedCMD avatar Oct 03 '25 22:10 RedCMD