Skip to content

Clean up user-submitted HTML, preserving whitelisted elements and whitelisted attributes on a per-element basis. Built on htmlparser2 for speed and tolerance

License

shanehh/sanitize-html

 
 

Repository files navigation

origin repo: https://github.com/apostrophecms/sanitize-html

I have hacked it to add disallowedStyles for special purpose.

const r = sanitizeHtml(
  "<span style='color: blue; text-align: justify; font-family: helvetica'></span>",
  {
    allowedTags: false,
    allowedAttributes: {
      span: ["style"],
    },
    disallowedStyles: ["text-align", "font-family"],
  }
);

r === '<span style="color:blue"></span>';

About

Clean up user-submitted HTML, preserving whitelisted elements and whitelisted attributes on a per-element basis. Built on htmlparser2 for speed and tolerance

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%