Skip to content

Commit

Permalink
Fix #204
Browse files Browse the repository at this point in the history
Also fix a just-introduced minor bug
  • Loading branch information
sergiocorreia committed Jul 14, 2022
1 parent 2d6b21a commit 893d8b9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
4 changes: 2 additions & 2 deletions panflute/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def insert(self, i, v):
v = check_type(v, self.oktypes)
self.list.insert(i, v)

def walk(self, action, doc, stop_if):
def walk(self, action, doc=None, stop_if=None):
ans = (item.walk(action, doc, stop_if) for item in self)
# We need to convert single elements to iterables that can be flattened later
ans = ((item,) if type(item) is not list else item for item in ans)
Expand Down Expand Up @@ -135,7 +135,7 @@ def __setitem__(self, k, v):
v = check_type(v, self.oktypes)
self.dict[k] = v

def walk(self, action, doc, stop_if):
def walk(self, action, doc=None, stop_if=None):
ans = ((k, v.walk(action, doc, stop_if)) for k, v in self.items())
ans = [(k, v) for k, v in ans if v != []]
return ans
Expand Down
6 changes: 3 additions & 3 deletions panflute/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def stringify(element, newlines=True):
"""

def stop_if(e):
return isinstance(e, DefinitionList)
return isinstance(e, (DefinitionList, Cite))

def attach_str(e, doc, answer):
if hasattr(e, 'text'):
Expand All @@ -264,8 +264,8 @@ def attach_str(e, doc, answer):
definitions = '; '.join(stringify(defn) for defn in item.definitions)
ans.append(f'- {term}: {definitions}')
ans = '\n'.join(ans)
elif type(e) == Citation:
ans = ''
elif type(e) == Cite:
ans = stringify(e.content)
else:
ans = ''

Expand Down
2 changes: 1 addition & 1 deletion panflute/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Panflute version
"""

__version__ = '2.2.0'
__version__ = '2.2.1'
15 changes: 14 additions & 1 deletion tests/test_stringify.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import panflute as pf


def validate(markdown_text, expected_text):
def validate(markdown_text, expected_text, verbose=False):
doc = pf.convert_text(markdown_text, input_format='markdown', output_format='panflute', standalone=True)
output_text = pf.stringify(doc)
if verbose:
print('<<<< EXPECTED <<<<')
print(expected_text)
print('<<<< OUTPUT <<<<')
print(output_text)
print('>>>>>>>>>>>>>>>>')
assert expected_text == output_text


Expand All @@ -13,6 +19,12 @@ def test_simple():
validate(markdown_text, expected_text)


def test_cite():
markdown_text = '[@abc, p.23]'
expected_text = '[@abc, p.23]\n\n'
validate(markdown_text, expected_text)


def test_definition_list():
markdown_text = '''Term 1\n: Definition 1\n\nTerm 2 with *inline markup*\n\n: Definition 2'''
expected_text = '''- Term 1: Definition 1\n- Term 2 with inline markup: Definition 2\n\n'''
Expand All @@ -27,5 +39,6 @@ def test_definition_list_complex():

if __name__ == "__main__":
test_simple()
test_cite()
test_definition_list()
test_definition_list_complex()

0 comments on commit 893d8b9

Please sign in to comment.