This change does two things to permit custom rendering of footnote references in the RichTextBlockWithFootnotes block:
Moves reference rendering from an inner function in the replace_footnote_tags() method to a separate render_footnote_tag() method on the RichTextBlockWithFootnotes block class. This provides an easy extension point for subclasses of RichTextBlockWithFootnotes to customize rendering that doesn't require duplication of a lot of other code.
The default implementation of render_footnote_tag renders using a Django template, optionally set with the WAGTAIL_FOOTNOTES_REFERENCE_TEMPLATE setting, allowing users to override rendering by providing a different template to that setting.
This is similar in spirit to @an-ant0ni0's proposal in #27, however we've chosen to move rendering out of Python f-strings altogether and into Django (or any other configured engine's) templates.
The motivation here, is we're adopting this package to replace our hand-crafted (😱) footnotes, and our existing style doesn't include [] brackets around the reference number.
This will allow that kind of customization of reference rendering so users can render however their style specifies without having to subclass RichTextBlockWithFootnotes and include the full code of the replace_footnote_tags() with a single line f-string change. Instead, users will just have to provide a template.
This change does two things to permit custom rendering of footnote references in the
RichTextBlockWithFootnotes
block:replace_footnote_tags()
method to a separaterender_footnote_tag()
method on theRichTextBlockWithFootnotes
block class. This provides an easy extension point for subclasses ofRichTextBlockWithFootnotes
to customize rendering that doesn't require duplication of a lot of other code.render_footnote_tag
renders using a Django template, optionally set with theWAGTAIL_FOOTNOTES_REFERENCE_TEMPLATE
setting, allowing users to override rendering by providing a different template to that setting.This is similar in spirit to @an-ant0ni0's proposal in #27, however we've chosen to move rendering out of Python f-strings altogether and into Django (or any other configured engine's) templates.
The motivation here, is we're adopting this package to replace our hand-crafted (😱) footnotes, and our existing style doesn't include
[]
brackets around the reference number.This will allow that kind of customization of reference rendering so users can render however their style specifies without having to subclass
RichTextBlockWithFootnotes
and include the full code of thereplace_footnote_tags()
with a single line f-string change. Instead, users will just have to provide a template.