Skip to content

Commit

Permalink
🐛 fixed: crashes with text between underscores (#3)
Browse files Browse the repository at this point in the history
Underscored text is group 2 in Emphasis.pattern (such confuse).
  • Loading branch information
miyuchina committed Aug 14, 2017
1 parent d86c613 commit 9b14828
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion mistletoe/span_tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ def tokenize(content, token_types, fallback_token):
# there's text between our current position and the next token
yield fallback_token(content[index:min_index])
if min_match_obj: # min_match_obj is not None
yield min_token_type(min_match_obj.group(1))
yield min_token_type(_first_not_none_group(min_match_obj))
index += min_match_obj.end() # update pointer
else: return # min_match_obj is None; no more tokens

def _first_not_none_group(match_obj):
return next(group for group in match_obj.groups() if group is not None)
5 changes: 5 additions & 0 deletions test/test_span_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ def test_raw(self):
c = span_token.RawText('some text')
helpers.check_equal(self, list(t.children)[0], c)

def test_parse(self):
t = span_token.Strong('_some text_')
c = span_token.Emphasis('some text')
helpers.check_equal(self, list(t.children)[0], c)

class TestInlineCode(unittest.TestCase):
def test_raw(self):
t = span_token.InlineCode('some code')
Expand Down

0 comments on commit 9b14828

Please sign in to comment.