Apply classes in Markdown filter through a Bleach filter
This PR adds ClassApplyFilter
, a Bleach filter that lets you specify a set of HTML tags to apply a set of classes to. This lets us e.g. apply table table-striped
classes to all tables, required for Bootstrap's styling. Our previous implementation for this used a Markdown extension, but this was not sufficient because the extension did not catch elements added to the element tree late in Markdown filter. The Bleach filter, in contrast, catches all elements.
Catching all elements lets us apply img-fluid
to img
elements. This was previously impossible, requiring us to apply the styling of this class to all img
elements, indiscriminately, through base.css
. In addition, images are now centered.
Setting text-break
to anchors is now done through this new filter, instead of through LinkifyFilter
. This change might be debateable, but I strongly prefer keeping this sort of logic located in the same place, going through the same function.
Lastly, this PR short-circuits a conditional in the sidebar
template tag. This template tag is, for some reason, often called with user
set to None
when there are exceptions elsewhere, leading to an AttributeError
in the conditional, which hides the actual error in the log. Short-circuiting if user
doesn't exist is a simple way to solve this issue.