Fix markdown styling for rendered images (#2125)

fix md styling for rendered images
This commit is contained in:
Sean Hatfield 2024-08-15 12:17:05 -07:00 committed by GitHub
parent 99f2c25b1c
commit fd16773295
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -44,7 +44,19 @@ const markdown = markdownIt({
"</pre></div>"
);
},
}).use(markdownItKatex);
});
// Custom renderer for responsive images rendered in markdown
markdown.renderer.rules.image = function (tokens, idx) {
const token = tokens[idx];
const srcIndex = token.attrIndex("src");
const src = token.attrs[srcIndex][1];
const alt = token.content || "";
return `<div class="w-full max-w-[800px]"><img src="${src}" alt="${alt}" class="w-full h-auto" /></div>`;
};
markdown.use(markdownItKatex);
export default function renderMarkdown(text = "") {
return markdown.render(text);