-
Hi I'm getting this output by using Shiki and this code #2122 (comment) is there a way to tell marked not to create its |
Beta Was this translation helpful? Give feedback.
Answered by
UziTech
Nov 20, 2022
Replies: 1 comment 4 replies
-
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;
}
return false;
}
}
};
const markedCallback = (err, html) => {
if (err) return reject(err);
resolve(html);
};
marked.use(markedOptions);
marked(markdown, markedCallback);
});
}
console.log(await markdownToHtml("```js\nconsole.log('test');\n```\n")); |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
babakfp
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can change the code renderer to not always wrap the code in pre and code tags. This code seems to work: