Browse Source

Remove optional whitespace from short image markdown (#1290)

* Add vim temp files to gitignore

* Remove optional whitespace from short image markdown
Matthew Bowden 5 years ago
parent
commit
f58fe88889

+ 1 - 0
.gitignore

@@ -50,6 +50,7 @@ pylint.txt
 # IDEs
 .idea/
 .vscode/
+*.swp
 
 # Django stuff:
 *.log

+ 1 - 1
misago/markup/md/shortimgs.py

@@ -2,7 +2,7 @@ import markdown
 from markdown.inlinepatterns import LinkPattern
 from markdown.util import etree
 
-IMAGES_RE = r"\!(\s?)\((<.*?>|([^\)]*))\)"
+IMAGES_RE = r"\!\((<.*?>|([^\)]*))\)"
 
 
 class ShortImagesExtension(markdown.Extension):

+ 11 - 1
misago/markup/tests/snapshots/snap_test_short_image_markdown.py

@@ -8,5 +8,15 @@ from snapshottest import Snapshot
 snapshots = Snapshot()
 
 snapshots[
-    "test_short_image_markdown 1"
+    "test_short_image_markdown[base] 1"
 ] = '<p><img alt="somewhere.com/image.jpg" src="http://somewhere.com/image.jpg"/></p>'
+snapshots["test_short_image_markdown[space-one-word] 1"] = "<p>! (space)</p>"
+snapshots[
+    "test_short_image_markdown[space-multiple-words] 1"
+] = "<p>! (space with other words)</p>"
+snapshots[
+    "test_short_image_markdown[text-before-mark] 1"
+] = '<p>Text before exclamation mark<img alt="somewhere.com/image.jpg" src="http://somewhere.com/image.jpg"/></p>'
+snapshots[
+    "test_short_image_markdown[text-before-with-space] 1"
+] = "<p>Text before with space in between! (sometext)</p>"

+ 18 - 2
misago/markup/tests/test_short_image_markdown.py

@@ -1,7 +1,23 @@
+import pytest
+
 from ..parser import parse
 
 
-def test_short_image_markdown(request_mock, user, snapshot):
-    text = "!(http://somewhere.com/image.jpg)"
+@pytest.mark.parametrize(
+    "text",
+    [
+        pytest.param("!(http://somewhere.com/image.jpg)", id="base"),
+        pytest.param("! (space)", id="space-one-word"),
+        pytest.param("! (space with other words)", id="space-multiple-words"),
+        pytest.param(
+            "Text before exclamation mark!(http://somewhere.com/image.jpg)",
+            id="text-before-mark",
+        ),
+        pytest.param(
+            "Text before with space in between! (sometext)", id="text-before-with-space"
+        ),
+    ],
+)
+def test_short_image_markdown(request_mock, user, snapshot, text):
     result = parse(text, request_mock, user, minify=False)
     snapshot.assert_match(result["parsed_text"])