fix(Sanitizer): read options from config
Resolve https://github.com/basecamp/trix/issues/1178 by making the sanitizer options configurable.
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., iframe for those allowing the embedding of YouTube videos); see https://github.com/basecamp/trix/issues/1178 for more details.
https://github.com/basecamp/trix/pull/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 data-keyword) to a tags. This would only work with your @Betree's fix and adding it to the textAttributes in the config. For example:
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 allowedAttributes (or having it in textAttributes) should be enough to get it to work, but at least this improves on not working at all.