Skip to content

Commit

Permalink
Fix Python 3.11 global flags not at the start of the regex expression -
Browse files Browse the repository at this point in the history
  • Loading branch information
Benbb96 committed Jan 5, 2023
1 parent 4b7a008 commit 77550be
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/wiki/plugins/images/markdown_extensions.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import re

import markdown
from django.template.loader import render_to_string
from wiki.core.markdown import add_to_registry
from wiki.plugins.images import models
from wiki.plugins.images import settings

IMAGE_RE = (
r"(?:(?im)"
r"(?:"
+
# Match '[image:N'
r"\[image\:(?P<id>[0-9]+)"
Expand Down Expand Up @@ -53,6 +55,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
Expand Down
9 changes: 8 additions & 1 deletion src/wiki/plugins/macros/mdx/macro.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# http://stackoverflow.com/questions/430759/regex-for-managing-escaped-characters-for-items-like-string-literals
re_sq_short = r"'([^'\\]*(?:\\.[^'\\]*)*)'"

MACRO_RE = r"((?i)\[(?P<macro>\w+)(?P<kwargs>\s\w+\:.+)*\])"
MACRO_RE = r"(\[(?P<macro>\w+)(?P<kwargs>\s\w+\:.+)*\])"
KWARG_RE = re.compile(
r"\s*(?P<arg>\w+)(:(?P<value>([^\']+|%s)))?" % re_sq_short, re.IGNORECASE
)
Expand All @@ -32,6 +32,13 @@ class MacroPattern(markdown.inlinepatterns.Pattern):
"""django-wiki macro preprocessor - parse text for various [some_macro] and
[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()
if macro not in settings.METHODS or not hasattr(self, macro):
Expand Down

0 comments on commit 77550be

Please sign in to comment.