Skip to content

Commit eff892a

Browse files
author
Pietro Albini
committed
Fix syntaxes matching not working sometimes (fixes #26)
Before this commit, automatic syntaxes matching wasn't working if there were characters before the part with the syntax markers. This commit fixes that and adds unit tests in order to prevent regressions.
1 parent a571729 commit eff892a

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

botogram/syntaxes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@
99
import re
1010

1111

12-
_markdown_re = re.compile(r"("
12+
_markdown_re = re.compile(r".*("
1313
r"\*(.*)\*|"
1414
r"_(.*)_|"
1515
r"\[(.*)\]\((.*)\)|"
1616
r"`(.*)`|"
1717
r"```(.*)```"
18-
r")")
18+
r").*")
1919

20-
_html_re = re.compile(r"("
20+
_html_re = re.compile(r".*("
2121
r"<b>(.*)<\/b>|"
2222
r"<strong>(.*)<\/strong>|"
2323
r"<i>(.*)<\/i>|"
2424
r"<em>(.*)<\/em>|"
2525
r"<a\shref=\"(.*)\">(.*)<\/a>|"
2626
r"<code>(.*)<\/code>|"
2727
r"<pre>(.*)<\/pre>"
28-
r")")
28+
r").*")
2929

3030

3131
def is_markdown(message):

tests/test_syntaxes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ def test_is_markdown():
1616

1717
for delimiter in "*", "_", "`", "```":
1818
assert botogram.syntaxes.is_markdown(delimiter+"a"+delimiter)
19+
assert botogram.syntaxes.is_markdown("!"+delimiter+"a"+delimiter+"!")
1920

2021
assert botogram.syntaxes.is_markdown("[a](b)")
22+
assert botogram.syntaxes.is_markdown("![a](b)!")
2123

2224

2325
def test_is_html():
@@ -26,10 +28,12 @@ def test_is_html():
2628

2729
for tag in "b", "strong", "i", "em", "pre", "code":
2830
assert botogram.syntaxes.is_html("<"+tag+">a</"+tag+">")
31+
assert botogram.syntaxes.is_html("!<"+tag+">a</"+tag+">!")
2932

3033
assert not botogram.syntaxes.is_html("<a>a</a>")
3134
assert not botogram.syntaxes.is_html("<a test=\"b\">a</a>")
3235
assert botogram.syntaxes.is_html("<a href=\"b\">a</a>")
36+
assert botogram.syntaxes.is_html("!<a href=\"b\">a</a>!")
3337

3438

3539
def test_guess_syntax():

0 commit comments

Comments
 (0)