From ed0aa1323a7acae363c670cc1dd6611c09e0c3fb Mon Sep 17 00:00:00 2001 From: Botond Hende Date: Thu, 8 Aug 2024 21:39:17 +0200 Subject: extended image handles foreign images --- extendedimage.py | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'extendedimage.py') diff --git a/extendedimage.py b/extendedimage.py index 4babc03..cec690f 100644 --- a/extendedimage.py +++ b/extendedimage.py @@ -11,6 +11,7 @@ Parameters can be encapsulated in double-quotes. Use "" for empty parameter. """ from marko import inline from marko.helpers import MarkoExtension +from . import utils class ExtendedImageElement(inline.InlineElement): @@ -32,20 +33,29 @@ class ExtendedImageElement(inline.InlineElement): return text -class ExtendedImageRenderer: - def render_extended_image_element(self, element): - img = f'{element.alt}' +def __create_image_renderer(filters: list[str]): + class ExtendedImageRenderer: + FILTERS = filters - if element.href != "": - img = f'{img}' + def render_extended_image_element(self, element): + img = f'{element.alt}' - if element.figcaption != "": - img = f"
{img}
{element.figcaption}
" + if element.href != "": + img = f'{img}' - return img + if element.figcaption != "": + img = f"
{img}
{element.figcaption}
" + return img -ExtendedImage = MarkoExtension( - elements=[ExtendedImageElement], - renderer_mixins=[ExtendedImageRenderer] -) + return ExtendedImageRenderer + + +def get_image_renderer(filters: list[str] = None): + if filters is None: + filters = [] + + return MarkoExtension( + elements=[ExtendedImageElement], + renderer_mixins=[__create_image_renderer(filters)] + ) -- cgit v1.2.3-70-g09d2