fix(Sanitizer): read options from config#1183
Conversation
| static sanitize(html, options) { | ||
| const sanitizer = new this(html, options) | ||
| sanitizer.sanitize() | ||
| return sanitizer | ||
| } | ||
|
|
There was a problem hiding this comment.
I removed this function since it wasn't used, and to prevent any confusion with the non-static sanitize method
|
This looks great! |
|
@jorgemanrubia, do you have any feedback on the approach implemented here? Some of us are still struggling with custom tags and attributes (e.g., #1208 was a first step in the right direction, but it was apparently not enough to support the use case mentioned above. I'd gladly rebase & adjust the changes here according to your feedback! |
|
I've made an updated fork with your modifications and the current version of main: https://github.com/oktaal/trix/tree/fix/sanitizer-config I've ran into this issue where I needed to add a custom attribute (in my case document.addEventListener("trix-before-initialize", () => {
Trix.config.textAttributes['data-keyword'] = {
groupTagName: "a",
parser(element) {
const matchingSelector = `a[data-keyword]`
const keyword = element.closest(matchingSelector)
if (keyword) {
return keyword.getAttribute("data-keyword")
}
}
};
Trix.config.parser.allowedAttributes = "style href src width height language class data-keyword".split(" ")
});Ideally just having the attribute in the |
Resolve #1178 by making the sanitizer options configurable.