Files
progcode/docs/design-system/kit-completeness/reference-source/scripts/publication-sanitizer.mjs
T
huncode 12562baeb5
Build and deploy / deploy (push) Successful in 2m39s
Implement ProgCode identity and real shared reading UI kit
2026-10-27 15:19:49 +03:00

10 lines
1015 B
JavaScript

import sanitizeHtml from 'sanitize-html';
export function cleanPublication(html){return sanitizeHtml(html,{
allowedTags:['p','h2','h3','h4','pre','code','strong','em','b','i','ul','ol','li','blockquote','figure','figcaption','img','table','thead','tbody','tr','th','td','br','a'],
allowedAttributes:{a:['href','title','rel'],img:['src','alt','width','height','loading','decoding'],h2:['id'],h3:['id'],h4:['id'],pre:['tabindex','aria-label']},
allowedSchemes:['https','http'],allowProtocolRelative:false,
transformTags:{a:(tag,attrs)=>({tagName:tag,attribs:{href:attrs.href||'',rel:'noopener noreferrer'}}),pre:(tag,attrs)=>({tagName:tag,attribs:{tabindex:'0','aria-label':'Пример кода, прокрутка клавишами со стрелками'}})},
exclusiveFilter:frame=>frame.tag==='img'&&(!frame.attribs.src?.startsWith('/visuals/')||frame.attribs.src.startsWith('//')),
disallowedTagsMode:'discard',nonTextTags:['script','style','textarea','option','iframe','object','embed','form'],
});}