Reputation: 2840
i'm trying to allow relative urls in images src attribute as well as absolute ones. I can't get this done. If the parser rule setting for "src" is "url" only absolute urls are allowed and all the relative ones are stripped. If i set it to href all src attributes are thrown away. Somehow this happens on sending.
I thought href would be the right parser rule as mentioned in the docs.
Here is the description from https://github.com/xing/wysihtml5/blob/master/parser_rules/advanced.js
- href: allows something like "mailto:[email protected]", "http://google.com", "/foobar.jpg"
Any Ideas?
Upvotes: 0
Views: 582
Reputation: 1800
I realise this is quite an old question but hopefully this will be useful to someone else.
I had this same issue using wysihtml5-0.3.0. The "src" method appears to have been removed so setting "src": "src" in the parser rules wasn't working for me. To remedy this, as well as setting "src" : "src" in the parser rules, I've updated the the wysihtml5-x.x.x.js file by adding the following to "var attributeCheckMethods":
src: (function () {
return function (attributeValue) {
return attributeValue;
}
})()
This will allow the src to be returned exactly as it was entered. This introduce a risk if it's operating in an insecure environment. The particular system I'm building has restricted access to just a handful of people so it's not an issue for me but if you want to use this publicly you may want to validate with a regular expression first.
Hope this is of help to someone.
Upvotes: 1
Reputation: 1162
Use a parser rule like:
"img": {
"check_attributes": {
"width": "numbers",
"alt": "alt",
"src": "src", // https://github.com/xing/wysihtml5/blob/master/parser_rules/advanced.js#L97
"height": "numbers"
},
"add_class": {
"align": "align_img"
}
},
Upvotes: 0