
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
xhtml-purifier
Advanced tools
Forked from the wonderful javascript-xhtml-purifier
This script provides a method to cleanup dirty html. It will take a string of dirty and badly formatted html, and return a pretty printed valid XHTML string.
require('xhtml-purifier').purify(html_string);
The purifying is based on section 8.2 in the HTML5 specification, and implements a subset of the algorithm described there.
Only a limited set of the permitted HTML5 elements and attributes are permitted, and all other tags/attributes will simply be gone in the resulting XHTML.
All other elements will be stripped from the resulting XHTML, although the inner text will be left intact.
The script was originally created for use with a Rich Text Editor for a CMS, and purposefully puts very firm limits on what can be included in the resulting XHTML. Since it is based on the HTML5 parsing specification it is very robust when it comes to cleaning up tag soup.
Copyright © 2014 Charlie Stigler with Zaption and released under the MIT license.
Based on javascript-html-purifier, which is copyright © 2008 Mathias Biilmann Christensen / Domestika INTERNET S.L., released under the MIT license (see MIT-LICENSE)
Includes John Resig's and Erik Arvidsson's HTML Parser, which is used as a tokenizer.
HTML Parser By John Resig (ejohn.org) Original code by Erik Arvidsson, Mozilla Public License http://erik.eae.net/simplehtmlparser/simplehtmlparser.js
FAQs
Simple HTML purifier/cleaner for untrusted HTML.
The npm package xhtml-purifier receives a total of 672 weekly downloads. As such, xhtml-purifier popularity was classified as not popular.
We found that xhtml-purifier demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.