Skip to content

Commit

Permalink
Fix duplicate tags when decoding MPL2 (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
devcompl authored and otsaloma committed Nov 9, 2017
1 parent 5f39400 commit d6a8049
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion aeidon/markups/mpl2.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import aeidon

from collections import OrderedDict

__all__ = ("MPL2",)


Expand Down Expand Up @@ -78,7 +80,7 @@ def _pre_decode_identify(self, text):
match = re_tag.search(line)
if match is None: continue
lines[i] = match.group(2)
for tag in reversed(match.group(1)):
for tag in reversed(OrderedDict.fromkeys(match.group(1))):
lines[i] = "<{}>{}</{}>".format(tag, lines[i], tag)
return "\n".join(lines)

Expand Down
7 changes: 7 additions & 0 deletions aeidon/markups/test/test_mpl2.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ def test_decode__multiple(self):
"<i><u>All things weird are normal</u></i>\n"
"<b><i><u>in this whore of cities.</u></i></b>")

def test_decode__duplicate(self):
text = ("//All things weird are normal\n"
"/_/_in this whore of cities.")
assert self.markup.decode(text) == (
"<i>All things weird are normal</i>\n"
"<i><u>in this whore of cities.</u></i>")

def test_decode__underline(self):
text = ("All things weird are normal\n"
"_in this whore of cities.")
Expand Down

0 comments on commit d6a8049

Please sign in to comment.