mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-04 23:09:50 +00:00
add target=blank to each anchor
This commit is contained in:
parent
95ee573dc5
commit
d0af191a00
@ -120,10 +120,28 @@ const truncateContent = (content: string): string => {
|
|||||||
return truncatedContent;
|
return truncatedContent;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const preprocess = (markdown: string): string => {
|
||||||
|
return markdown;
|
||||||
|
}
|
||||||
|
|
||||||
|
const postprocess = (html: string): string => {
|
||||||
|
DOMPurify.addHook('afterSanitizeAttributes', (node) => {
|
||||||
|
if ('target' in node) {
|
||||||
|
node.setAttribute('target', '_blank');
|
||||||
|
node.setAttribute('rel', 'noopener noreferrer');
|
||||||
|
}
|
||||||
|
if (!node.hasAttribute('target') && (node.hasAttribute('xlink:href') || node.hasAttribute('href'))) {
|
||||||
|
node.setAttribute('xlink:show', 'new');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return DOMPurify.sanitize(html);
|
||||||
|
}
|
||||||
|
|
||||||
const convertMarkdownToHtml = (markdown: string): string => {
|
const convertMarkdownToHtml = (markdown: string): string => {
|
||||||
|
marked.use({'hooks': {postprocess, preprocess}});
|
||||||
const rawHtml = marked(markdown);
|
const rawHtml = marked(markdown);
|
||||||
// console.log(rawHtml)
|
return rawHtml;
|
||||||
return DOMPurify.sanitize(rawHtml)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const prepareContent = (content: string): string => {
|
const prepareContent = (content: string): string => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user