From 79a76731549087611b3cb6087f22088209f494ad Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Fri, 5 Oct 2012 17:08:47 +0200 Subject: [PATCH] Add `allow_attributes` parser rule option to do just that. --- parser_rules/advanced.js | 6 ++++++ parser_rules/simple.js | 3 +++ src/dom/parse.js | 14 +++++++++++++- test/dom/parse_test.js | 5 +++-- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/parser_rules/advanced.js b/parser_rules/advanced.js index bcbea6bc..f6d58f9e 100644 --- a/parser_rules/advanced.js +++ b/parser_rules/advanced.js @@ -179,6 +179,9 @@ var wysihtml5ParserRules = { "rename_tag": "div" }, "a": { + "allow_attributes": [ + "title" + ], "check_attributes": { "href": "url" // if you compiled master manually then change this from 'url' to 'href' }, @@ -188,6 +191,9 @@ var wysihtml5ParserRules = { } }, "img": { + "allow_attributes": [ + "title" + ], "check_attributes": { "width": "numbers", "alt": "alt", diff --git a/parser_rules/simple.js b/parser_rules/simple.js index 63a2e8b4..fceac12f 100644 --- a/parser_rules/simple.js +++ b/parser_rules/simple.js @@ -20,6 +20,9 @@ var wysihtml5ParserRules = { ol: {}, li: {}, a: { + allow_attributes: [ + "title" + ], set_attributes: { target: "_blank", rel: "nofollow" diff --git a/src/dom/parse.js b/src/dom/parse.js index f7868f94..039b6621 100644 --- a/src/dom/parse.js +++ b/src/dom/parse.js @@ -211,6 +211,7 @@ wysihtml5.dom.parse = (function() { var attributes = {}, // fresh new set of attributes to set on newNode setClass = rule.set_class, // classes to set addClass = rule.add_class, // add classes based on existing attributes + allowAttributes = rule.allow_attributes, // copy attributes from old to new node setAttributes = rule.set_attributes, // attributes to set on the current node checkAttributes = rule.check_attributes, // check/convert values of attributes allowedClasses = currentRules.classes, @@ -230,6 +231,17 @@ wysihtml5.dom.parse = (function() { if (setAttributes) { attributes = wysihtml5.lang.object(setAttributes).clone(); } + + if (allowAttributes) { + allowAttributesLength = allowAttributes.length; + for (i = 0; itake this you snorty little sanitizer' + '

yes, you!

' + '

i\'m old and ready to die

' + - '
' + + '
' + '
', rules ), '

take this you snorty little sanitizer

' + '

yes, you!

' + - 'foofoo' + + 'foofoo' + '' ); });