2025-01-26 16:31:47 -05:00
|
|
|
import { marked, Renderer } from 'marked';
|
|
|
|
|
|
2025-01-26 16:50:15 -05:00
|
|
|
// Customized renderer to support image width and height
|
|
|
|
|
// see https://github.com/markedjs/marked/issues/339#issuecomment-1146363560
|
2025-01-26 16:31:47 -05:00
|
|
|
const renderer = new Renderer();
|
|
|
|
|
|
|
|
|
|
renderer.image = ({href, title, text}) => {
|
|
|
|
|
const [width, height] = title?.startsWith('=') ? title.slice(1).split('x').map(v => v.trim()).filter(Boolean) : [];
|
|
|
|
|
return `<img src="${href}" alt="${text}"${width ? ` width="${width}"` : ''}${height ? ` height="${height}"` : ''}>`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
marked.use({
|
|
|
|
|
renderer: renderer
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export default marked;
|