0.8.0 • Published 6 days ago

shaku-code-annotate-shiki v0.8.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 days ago

shaku-code-annotate-shiki

(Shaku)- elucidate, explain

This module enables you to annotate your code snippet with separation from normal comments, makes it easier to explain the code. It uses shiki as backbone and inspired by shiki-twoslash.

npm.io

Take a look at the live demo from

  1. Shaku playground
  2. demo with Astro.
  3. demo with Next.js.

Usage

import { getShakuHighlighters } from "shaku-code-annotate-shiki";

// 1. get highlighters of one theme or multiple themes
const highlighters = await getShakuHighlighters({
  langs: [lang],
  // theme: 'github-light'
  themes: ["github-light", "github-dark"],
});

// 2. for each theme generate HTML from code
const html = highlighters
  .map(
    (highlighter) =>
      highlighter.codeToShakuHtml({
        code,
        options: {
          // you can disable shaku syntax by following flag
          // isShakuSyntaxEnabled: false,

          // by default, shaku escapes, but you can use following combination
          // to do custom markdown parsing
          useDangerousRawHtml: true,
          markdownToHtmlAndSanitize: (code) => html
          lang,
        },
      }).html
  )
  .join("\n");

Plugins

Generally it is better for you to choose the right plugin for your markdown engine.

  1. Remark - remark-shaku-code-annotate
  2. Marked - marked-shaku-code-annotate