Custom extensions in MarkdownBlock
rokdd opened this issue · 5 comments
Sorry for asking more but I am a big fan of markdown and it's system. So I thought it is worth to implement a icon library and implementented into the extensions (and this works):
WAGTAILMARKDOWN_EXTENSIONS = ["toc", "sane_lists",'home.extensions.iconfonts:IconFontsExtension']
But in the markdown it does not handle the result safe:
As you can see the other markdowns for bold text was working. So do I something wrong? What is the best way to fix..? The MarkdownBlock in a Streamfield so I can not set it safe in the template.
Hey @RoKondo,
At the moment the <i>
tag and the aria-*
tags are not in the list of allowed bleach tags/attributes as per https://github.com/torchbox/wagtail-markdown/blob/main/wagtailmarkdown/utils.py#L39
#59 does provide the means for custom extentions to extend the bleach configuration, but we went with with the #69 for custom extension. Will add to my list to look at. Having looked at the icon library extension, the changes in #59 would not have made any difference.
imho, the best way forward is to add another configuration option, something like:
WAGTAILMARKDOWN_BLEACH_ALLOWED_ATTRIBUTES = {
'*': ['class', 'title', 'style'],
'a': ['href', 'target', 'rel']
# ...
'i': ['aria-hidden'],
}
which could then be merged with the default attributes list - https://github.com/torchbox/wagtail-markdown/blob/main/wagtailmarkdown/utils.py#L78
I guess this should be a good option because I already saw that others also wished the sup
tag for example #58 . IMHO there should be also a option for WAGTAILMARKDOWN_BLEACH_ALLOWED_TAGS
. Because as I am not mistaken it does not help to add only the attributes..?
True that. Will look at providing a unified setting WAGTAILMARKDOWN
that would be a dict of the various other settings. Django Rest Framework and others do it similarly. Unless, of course, you happen to have some spare time to submit a PR :D