Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Port of the google html sanitizer library
JavaScript
branch: master
Failed to load latest commit information.
node_modules got it working
test added smart sanitize
.gitignore Initial commit
LICENSE adding a license. wooo.
README.md added smart sanitize
package.json Updating build of caja
sanitizer.js adding a license. wooo.

README.md

node-caja-sanitizer

Port of the google caja html sanitizer library.

Use

Require the library and go

var sanitizer = require('html-css-sanitizer');
function urlX(u) { return u } //url transformer (noop here)
function idX(id) { return id } //id transformer (noop here)
function sanitize (string) {
  return sanitizer.sanitize(string, urlX, idX);
}
var result = sanitize('test<script>console.log("hi there");</script>');

The default caja library doesn't handle self-closing tags in the best way, so I'm stealing a pull request from isaacs to create a smartSanitize method. To use that, do this:

function smartSanitize (string) {
  return sanitizer.smartSanitize(string, urlX, idX);
}
result = smartSanitize('<p><a name="foo"/> This is the foo section.</p><p><a name="bar"/> This is the bar section.</p>');

I'm NOT overwriting the original caja sanitize call because.

More info

https://code.google.com/p/google-caja/wiki/JsHtmlSanitizer

Something went wrong with that request. Please try again.