Skip to content

Commit

Permalink
Fix syntaxes matching not working sometimes (fixes #26)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Pietro Albini committed Feb 20, 2016
1 parent a571729 commit eff892a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 4 additions & 4 deletions botogram/syntaxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@
import re


_markdown_re = re.compile(r"("
_markdown_re = re.compile(r".*("
r"\*(.*)\*|"
r"_(.*)_|"
r"\[(.*)\]\((.*)\)|"
r"`(.*)`|"
r"```(.*)```"
r")")
r").*")

_html_re = re.compile(r"("
_html_re = re.compile(r".*("
r"<b>(.*)<\/b>|"
r"<strong>(.*)<\/strong>|"
r"<i>(.*)<\/i>|"
r"<em>(.*)<\/em>|"
r"<a\shref=\"(.*)\">(.*)<\/a>|"
r"<code>(.*)<\/code>|"
r"<pre>(.*)<\/pre>"
r")")
r").*")


def is_markdown(message):
Expand Down
4 changes: 4 additions & 0 deletions tests/test_syntaxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ def test_is_markdown():

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

assert botogram.syntaxes.is_markdown("[a](b)")
assert botogram.syntaxes.is_markdown("![a](b)!")


def test_is_html():
Expand All @@ -26,10 +28,12 @@ def test_is_html():

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

assert not botogram.syntaxes.is_html("<a>a</a>")
assert not botogram.syntaxes.is_html("<a test=\"b\">a</a>")
assert botogram.syntaxes.is_html("<a href=\"b\">a</a>")
assert botogram.syntaxes.is_html("!<a href=\"b\">a</a>!")


def test_guess_syntax():
Expand Down

0 comments on commit eff892a

Please sign in to comment.