From 5f581a5311624cfe43a214c63890764dac8a0e6f Mon Sep 17 00:00:00 2001 From: Peter Sanchez Date: Wed, 1 Mar 2023 16:28:24 -0600 Subject: [PATCH] Py 3.11 changes --- src/wiki/plugins/images/markdown_extensions.py | 14 ++++++++++++-- src/wiki/plugins/macros/mdx/macro.py | 13 ++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/wiki/plugins/images/markdown_extensions.py b/src/wiki/plugins/images/markdown_extensions.py index 59a39519..8acb70c9 100644 --- a/src/wiki/plugins/images/markdown_extensions.py +++ b/src/wiki/plugins/images/markdown_extensions.py @@ -1,10 +1,12 @@ +import re + import markdown from django.template.loader import render_to_string from wiki.plugins.images import models from wiki.plugins.images import settings IMAGE_RE = ( - r"(?:(?im)" + r"(?:" + # Match '[image:N' r"\[image\:(?P[0-9]+)" @@ -27,7 +29,7 @@ IMAGE_RE = ( class ImageExtension(markdown.Extension): - """ Images plugin markdown extension for django-wiki. """ + """Images plugin markdown extension for django-wiki.""" def extendMarkdown(self, md): md.inlinePatterns.add("dw-images", ImagePattern(IMAGE_RE, md), ">link") @@ -47,6 +49,14 @@ class ImagePattern(markdown.inlinepatterns.Pattern): So: Remember that the caption text is fully valid markdown! """ + def __init__(self, pattern, md=None): + """Override init in order to add IGNORECASE and MULTILINE flags""" + super().__init__(pattern, md=md) + self.compiled_re = re.compile( + r"^(.*?)%s(.*)$" % pattern, + flags=re.DOTALL | re.UNICODE | re.IGNORECASE | re.MULTILINE, + ) + def handleMatch(self, m): image = None image_id = None diff --git a/src/wiki/plugins/macros/mdx/macro.py b/src/wiki/plugins/macros/mdx/macro.py index 88246e48..e2c5aa8f 100644 --- a/src/wiki/plugins/macros/mdx/macro.py +++ b/src/wiki/plugins/macros/mdx/macro.py @@ -9,7 +9,7 @@ from wiki.plugins.macros import settings # http://stackoverflow.com/questions/430759/regex-for-managing-escaped-characters-for-items-like-string-literals re_sq_short = r"'([^'\\]*(?:\\.[^'\\]*)*)'" -MACRO_RE = r"((?i)\[(?P\w+)(?P\s\w+\:.+)*\])" +MACRO_RE = r"(\[(?P\w+)(?P\s\w+\:.+)*\])" KWARG_RE = re.compile( r"\s*(?P\w+)(:(?P([^\']+|%s)))?" % re_sq_short, re.IGNORECASE ) @@ -17,7 +17,7 @@ KWARG_RE = re.compile( class MacroExtension(markdown.Extension): - """ Macro plugin markdown extension for django-wiki. """ + """Macro plugin markdown extension for django-wiki.""" def extendMarkdown(self, md): md.inlinePatterns.add("dw-macros", MacroPattern(MACRO_RE, md), ">link") @@ -26,7 +26,14 @@ class MacroExtension(markdown.Extension): class MacroPattern(markdown.inlinepatterns.Pattern): """django-wiki macro preprocessor - parse text for various [some_macro] and - [some_macro (kw:arg)*] references. """ + [some_macro (kw:arg)*] references.""" + + def __init__(self, pattern, md=None): + """Override init in order to add IGNORECASE flag""" + super().__init__(pattern, md=md) + self.compiled_re = re.compile( + r"^(.*?)%s(.*)$" % pattern, flags=re.DOTALL | re.UNICODE | re.IGNORECASE + ) def handleMatch(self, m): macro = m.group("macro").strip() -- 2.45.2