17 lines
1.0 KiB
JavaScript
17 lines
1.0 KiB
JavaScript
import {marked,DOMPurify} from './vendor/richtext.mjs?v=0.12.6';
|
|
|
|
const noticeTagPath = '/theme/Fuc/assets/native/images/brand/fuc-notice-tag.svg';
|
|
|
|
export function richText(value) {
|
|
const html=marked.parse(String(value||''),{async:false});
|
|
const sanitized=DOMPurify.sanitize(html,{ALLOWED_TAGS:['p','br','strong','b','em','i','ul','ol','li','h1','h2','h3','h4','h5','h6','blockquote','code','pre','a','img','table','thead','tbody','tr','th','td','hr','details','summary','div','span'],ALLOWED_ATTR:['href','src','alt','title','colspan','rowspan'],ALLOW_DATA_ATTR:false});
|
|
if (!sanitized.includes(noticeTagPath)) return '<div data-fuc-richtext>'+sanitized+'</div>';
|
|
|
|
// Use the same glyph as existing dated notices, including those already saved as HTML.
|
|
const content = document.createElement('div');
|
|
content.setAttribute('data-fuc-richtext', '');
|
|
content.innerHTML = sanitized;
|
|
content.querySelectorAll(`img[src="${noticeTagPath}"]`).forEach(icon => icon.replaceWith('🏷️'));
|
|
return content.outerHTML;
|
|
}
|