Hacker News new | ask | show | jobs
by franciscop 1919 days ago
This is not new, but it's nice to spread awareness since it seems everyone loads it in the front-end nowadays and I've noticed that it also avoids the page moving around too much.

In https://documentation.page/ I'm using `markdown-it` with `prismjs` to generate the code snippets (see example on e.g. https://react-test.dev/). It's in fact a default helper, so you don't even need hacks:

    import MarkdownIt from "markdown-it";
    import Prism from "prismjs";

    function highlight(str, lang) {
      if (!lang || !Prism.languages[lang]) return;
      return Prism.highlight(str, Prism.languages[lang], lang);
    }

    const md = new MarkdownIt({ highlight }).use(...