fix: 自动为 Markdown 外部链接添加新标签页和安全属性
continuous-integration/drone/push Build is passing

This commit is contained in:
seahi committed 2026-09-07 20:49:46 +08:00
1 parent 45c09064d3
commit cfd41e2c83
1 file changed
+4 -4
+4 -4
View File
@@ -90,13 +90,13 @@ export function sanitizeMarkdownHtml(html: string): string {
}, },
transformTags: { transformTags: {
a: (tagName, attribs) => { a: (tagName, attribs) => {
if (attribs.target === '_blank') { if (attribs['data-fancybox'] || (attribs.href && attribs.href.startsWith('#'))) {
return { tagName, attribs };
}
const rel = new Set((attribs.rel || '').split(/\s+/).filter(Boolean)); const rel = new Set((attribs.rel || '').split(/\s+/).filter(Boolean));
rel.add('noopener'); rel.add('noopener');
rel.add('noreferrer'); rel.add('noreferrer');
return { tagName, attribs: { ...attribs, rel: [...rel].join(' ') } }; return { tagName, attribs: { ...attribs, target: '_blank', rel: [...rel].join(' ') } };
}
return { tagName, attribs };
} }
} }
}); });