This commit is contained in:
th committed 2026-04-07 21:58:45 +02:00
1 parent a9603aa0e8
commit 719f9d51ff
13 files changed
+625 -70

No files matched your search

+19 -2
View File
@@ -3,11 +3,17 @@
import { esc } from './util.js';
import { state } from './state.js';
marked.use({ breaks: true, gfm: true });
marked.use({ breaks: true, gfm: true, renderer: {
link({ href, text }) {
const isExternal = /^https?:\/\//.test(href);
if (isExternal) return `<a href="${href}" target="_blank" rel="noopener">${text}</a>`;
return `<a href="${href}">${text}</a>`;
}
}});
const purifyConfig = {
ALLOWED_TAGS: ['h1','h2','h3','h4','h5','h6','p','br','hr','ul','ol','li','a','strong','em','del','code','pre','blockquote','table','thead','tbody','tr','th','td','img','input','span','div','audio','source'],
ALLOWED_ATTR: ['href','src','alt','width','height','type','checked','disabled','class','style','data-card-id','title','controls','preload'],
ALLOWED_ATTR: ['href','src','alt','width','height','type','checked','disabled','class','style','data-card-id','title','controls','preload','target','rel'],
ALLOW_DATA_ATTR: true,
};
@@ -33,6 +39,17 @@ function normalizeListBlock(block) {
export function renderMd(src) {
let processed = String(src || '').replace(/\r\n?/g, '\n')
// Gallery fenced block: ```gallery
.replace(/```gallery\s*\n([\s\S]*?)(?:```|$)/g, (_, content) => {
const imgs = [];
const imgRe = /!\[([^\]]*)\]\(([^)]+)\)/g;
let m;
while ((m = imgRe.exec(content)) !== null) imgs.push({ alt: m[1], src: m[2].split(/\s/)[0] });
if (!imgs.length) return '';
return '<div class="md-gallery">' + imgs.map(i =>
`<div class="md-gallery-item"><img src="${i.src}" alt="${esc(i.alt)}" loading="lazy"></div>`
).join('') + '</div>';
})
// Custom fenced list blocks: ```tree / ```bullets with or without closing ```
.replace(/```(tree|bullets)\s*\n([\s\S]*?)(?:```|$)/g, (_, kind, content) => {
const normalized = normalizeListBlock(content);