Skip to content

Commit e7e3e60

Browse files
authored
Replace tags in block render() too (#4)
1 parent 9215e17 commit e7e3e60

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

wagtail_footnotes/blocks.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ class RichTextBlockWithFootnotes(RichTextBlock):
1616
final template context.
1717
"""
1818

19-
def render_basic(self, value, context=None):
20-
html = super().render_basic(value, context)
21-
19+
def replace_footnote_tags(self, html, context=None):
2220
def replace_tag(match):
2321
try:
2422
index = self.process_footnote(match.group(1), context["page"])
@@ -28,6 +26,18 @@ def replace_tag(match):
2826
return f'<a href="#footnote-{index}" id="footnote-source-{index}"><sup>[{index}]</sup></a>'
2927
return mark_safe(FIND_FOOTNOTE_TAG.sub(replace_tag, html))
3028

29+
def render(self, value, context=None):
30+
if not self.get_template(context=context):
31+
return self.render_basic(value, context=context)
32+
33+
html = super().render(value, context=context)
34+
return self.replace_footnote_tags(html, context=context)
35+
36+
def render_basic(self, value, context=None):
37+
html = super().render_basic(value, context)
38+
39+
return self.replace_footnote_tags(html, context=context)
40+
3141
def process_footnote(self, footnote_id, page):
3242
footnotes = self.get_footnotes(page)
3343
footnote = page.footnotes.get(uuid=footnote_id)

0 commit comments

Comments
 (0)