Skip to content

Getting double pre and code elements #2659

Answered by UziTech
babakfp asked this question in Q&A
Discussion options

You must be logged in to vote

You can change the code renderer to not always wrap the code in pre and code tags. This code seems to work:

import { marked } from 'marked';
import shiki from 'shiki';

function markdownToHtml(markdown) {
  return new Promise((resolve, reject) => {
    const markedOptions = {
      highlight: (code, lang, callback) => {
        shiki
          .getHighlighter({ theme: 'nord' })
          .then(highlighter => {
            const result = highlighter.codeToHtml(code, lang);
            callback(null, result);
          })
          .catch(error => callback(error));
      },
      renderer: {
        code(code) {
          if (code.startsWith('<pre')) {
            return code;
          }

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@babakfp
Comment options

@UziTech
Comment options

@laygir
Comment options

@UziTech
Comment options

Answer selected by babakfp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants