M src/wiki/plugins/images/markdown_extensions.py => src/wiki/plugins/images/markdown_extensions.py +12 -2
@@ 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<id>[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
M src/wiki/plugins/macros/mdx/macro.py => src/wiki/plugins/macros/mdx/macro.py +10 -3
@@ 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<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
)
@@ 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()