From 5e6ef9294a384b9e436b1bf16d06305abea78bbf Mon Sep 17 00:00:00 2001 From: Mathias Rav Date: Fri, 3 Aug 2018 14:30:27 +0200 Subject: [PATCH] Don't require that [image] is by itself on the line --- src/wiki/plugins/images/markdown_extensions.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/wiki/plugins/images/markdown_extensions.py b/src/wiki/plugins/images/markdown_extensions.py index cd074a04..6819f264 100644 --- a/src/wiki/plugins/images/markdown_extensions.py +++ b/src/wiki/plugins/images/markdown_extensions.py @@ -3,19 +3,18 @@ from django.template.loader import render_to_string from wiki.plugins.images import models, settings IMAGE_RE = ( - # Match only at the beginning of a line - r"(?:(?im)^\s*" + + r"(?:(?im)" + # Match '[image:N' r"\[image\:(?P[0-9]+)" + # Match optional 'align' r"(?:\s+align\:(?Pright|left))?" + # Match optional 'size' r"(?:\s+size\:(?Pdefault|small|medium|large|orig))?" + - # Match ']' at end of line - r"\s*\]\s*$" + - # Match zero or more caption lines, each indented by four spaces. + # Match ']' and rest of line. # Normally [^\n] could be replaced with a dot '.', since '.' # does not match newlines, but inline processors run with re.DOTALL. + r"\s*\](?P[^\n]*)$" + + # Match zero or more caption lines, each indented by four spaces. r"(?P(?:\n [^\n]*)*))" ) @@ -62,6 +61,7 @@ class ImagePattern(markdown.inlinepatterns.Pattern): pass caption = m.group("caption") + trailer = m.group('trailer') caption_placeholder = "{{{IMAGECAPTION}}}" width = size.split("x")[0] if size else None @@ -78,7 +78,7 @@ class ImagePattern(markdown.inlinepatterns.Pattern): html_before, html_after = html.split(caption_placeholder) placeholder_before = self.markdown.htmlStash.store(html_before, safe=True) placeholder_after = self.markdown.htmlStash.store(html_after, safe=True) - return placeholder_before + caption + placeholder_after + return placeholder_before + caption + placeholder_after + trailer class ImagePostprocessor(markdown.postprocessors.Postprocessor): -- 2.45.2