sanitize-html

node v4.9.1
version: master
endpointsharetweet
const sanitizeHtml = require('sanitize-html'); var dirty = 'aaa<br style="baaa"><br>bb<br><br />c <span class="atwho-inserted" data-atwho-at-query="@" contenteditable="false"><a mtype="user" class="mention" mid="1">@Peter</a></span>&nbsp;, <span class="atwho-inserted" data-atwho-at-query="@t" contenteditable="false"><a class="mention" mid="2">@Tom</a></span>&nbsp;<br><br><span class="atwho-inserted" data-atwho-at-query="@pe" contenteditable="false"><a class="mention" mid="1">@Peter</a></span>&nbsp;<span class="atwho-query">@tom</span><br>ee<br><br>a';
Sanitize with some allowed tags
const mentions = []; const stage1 = sanitizeHtml(dirty, { allowedTags: ['a', 'br', 'nl'], allowedAttributes: { 'a': ['mid', 'mtype'], }, allowedClasses: { 'a': ['mention'] }, exclusiveFilter: function({ tag, attribs: { mid, mtype } = {}, text }) { if(tag === 'a' && mid) { mentions.push({ _id: mid, _type: mtype, text }); } return false; }, });
sanitizeHtml(stage1, { allowedTags: [], allowedAttributes: [], });
Loading…

no comments

    sign in to comment