From 7683c0d020b88e3ff338810034349f455c67a9f8 Mon Sep 17 00:00:00 2001 From: Erik Stein Date: Fri, 24 Aug 2018 10:07:35 +0200 Subject: [PATCH] prepared_richtext / get_prepared_richtext API for RichTextPlugins. --- content_plugins/base.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/content_plugins/base.py b/content_plugins/base.py index 5b870a2..0a9f31b 100644 --- a/content_plugins/base.py +++ b/content_plugins/base.py @@ -141,6 +141,13 @@ class RichTextBase(StyleMixin, FilesystemTemplateRendererPlugin): def __str__(self): return Truncator(strip_tags(self.richtext)).words(10, truncate=" ...") + @property + def prepared_richtext(self): + return mark_safe(self.get_prepared_richtext(self.richtext)) + + def get_prepared_richtext(self, richtext): + return richtext + # TODO Rename to SectionBreakBase class SectionBase(StyleMixin, FilesystemTemplateRendererPlugin): @@ -262,9 +269,10 @@ class FootnoteBase(StringRendererPlugin): class RichTextFootnoteMixin: MATCH_FOOTNOTES = re.compile("(\w+)") - def render(self): + def get_prepared_richtext(self, richtext): # Find all footnotes and convert them into links + richtext = super().get_prepared_richtext(richtext) rv = self.MATCH_FOOTNOTES.subn( '\" class="footnote">\">\g<1>', - self.richtext)[0] - return mark_safe(rv) + richtext)[0] + return rv