Skip to content

Commit

Permalink
flake8 cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ikirudennis committed Aug 9, 2024
1 parent 8a83b7d commit 9e604c0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
18 changes: 10 additions & 8 deletions tests/test_lists.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
from textile import Textile
from textile.objects.list import List


def test_lists():
t = Textile()
result = t.textileLists("* one\n* two\n* three")
expect = '\t<ul>\n\t\t<li>one</li>\n\t\t<li>two</li>\n\t\t<li>three</li>\n\t</ul>'
assert result == expect


def test_nested_list():
l = List('ol', indent_level=1)
l.add_item('li', 'test')
lst = List('ol', indent_level=1)
lst('li', 'test')
s = List('ol', indent_level=2)
s.add_item('li', 'another one')
l.add_item('li', s)
result = l.process()
lst('li', s)
result = lst()
expect = '\t<ol>\n\t\t<li>test\n\t\t<ol>\n\t\t\t<li>another one</li>\n\t\t</ol></li>\n\t</ol>'
assert result == expect

l = List('ol', indent_level=1)
l.add_item('li', 'test')
lst = List('ol', indent_level=1)
lst('li', 'test')
s1 = List('ol', indent_level=2)
s1.add_item('li', 'another one')
s2 = List('ul', indent_level=3)
s2.add_item('li', 'point one')
s2.add_item('li', 'point two')
s1.add_item('li', s2)
s1.add_item('li', 'moar item')
l.add_item('li', s1)
result = l.process()
lst('li', s1)
result = lst()
expect = '\t<ol>\n\t\t<li>test\n\t\t<ol>\n\t\t\t<li>another one\n\t\t\t<ul>\n\t\t\t\t<li>point one</li>\n\t\t\t\t<li>point two</li>\n\t\t\t</ul></li>\n\t\t\t<li>moar item</li>\n\t\t</ol></li>\n\t</ol>'
assert result == expect
20 changes: 10 additions & 10 deletions textile/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,16 +293,16 @@ def textileLists(self, text):
def fTextileList(self, match):
text = re.split(r'\n(?=[*#;:]+\s)', match.group(), flags=re.M)
pt = ''
result = []
# result = []
ls = OrderedDict()
for i, line in enumerate(text):
try:
nextline = text[i + 1]
except IndexError:
nextline = ''
# try:
# nextline = text[i + 1]
# except IndexError:
# nextline = ''

m = re.search(r"^(?P<tl>[#*;:]+)(?P<st>_|\d+)?(?P<atts>{0})[ .]?"
"(?P<content>.*)?$".format(cls_re_s), line, re.S)
"(?P<content>.*)?$".format(cls_re_s), line, re.S)
tl, start, atts, content = m.groups()
attributes = parse_attributes(atts)
content = content.strip()
Expand Down Expand Up @@ -373,15 +373,15 @@ def fTextileList(self, match):
_list.add_item(litem, content)
elif showitem:
# itemtag = ("\n{0}\t<{1}>{2}".format(tabs, litem, content) if
# showitem else '')
# showitem else '')
_sublist = List('{0}l'.format(ltype), attributes)
# line = "<{0}l{1}{2}>{3}".format(ltype, atts, start, itemtag)
_sublist.add_item(litem, content, attributes)
_list.add_item(litem, _sublist)
# line = _sublist.process()
else:
# line = ("\t<{0}{1}>{2}".format(litem, atts, content) if
# showitem else '')
# showitem else '')
_list.add_item(litem, content, attributes)
# line = '{0}{1}'.format(tabs, line)

Expand All @@ -404,8 +404,8 @@ def fTextileList(self, match):
# This else exists in the original php version. I'm not sure how
# to come up with a case where the line would not match. I think
# it may have been necessary due to the way php returns matches.
#else:
#line = "{0}\n".format(line)
# else:
# line = "{0}\n".format(line)
# result.append(line)
return self.doTagBr(litem, _list.process())

Expand Down
1 change: 1 addition & 0 deletions textile/objects/list.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from textile.utils import generate_tag


class List(object):
def __init__(self, listtype, attributes={}, indent_level=0):
super(List, self).__init__()
Expand Down

0 comments on commit 9e604c0

Please sign in to comment.