import MarkdownIt from "markdown-it"; const md = new MarkdownIt({ html: true, breaks: true, linkify: true, }); const mediaSrc = (folderName, fileName) => { return `/posts/${folderName}/${fileName}`; }; // Customize Markdown-to-HTML mapping here // md.renderer.rules.paragraph_open = () => '

'; md.renderer.rules.code_block = (tokens, idx, options, env, self) => { console.log("tokens", tokens); return `${tokens[idx].content}`; }; md.renderer.rules.image = (tokens, idx, options, env, self) => { // console.log('env', env) const token = tokens[idx]; const src = token.attrGet("src"); const alt = token.content; const postName = env.postName; const formattedSrc = mediaSrc(postName, src); if (src.endsWith(".mp4")) { return ``; } return `${alt}`; }; export function markdownToHtml(postName, content) { return md.render(content, { postName: postName }); }