Skip to content

Commit

Permalink
AST walking code no longer assumes that dict nodes have t (type) keys…
Browse files Browse the repository at this point in the history
…, fixing incompatibility with nodes generated by citations (#12)
  • Loading branch information
gpoore committed Dec 27, 2019
1 parent 423499f commit 911e103
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions codebraid/converters/pandoc.py
Expand Up @@ -482,10 +482,14 @@ def walk_node_list(node_list):
if isinstance(obj, list):
yield from walk_node_list(obj)
elif isinstance(obj, dict):
try:
node_type = obj['t']
except KeyError:
continue
yield (obj, node_list, index)
obj_contents = obj.get('c', None)
if isinstance(obj_contents, list):
if obj['t'] != 'DefinitionList':
if node_type != 'DefinitionList':
yield from walk_node_list(obj_contents)
else:
for elem in obj_contents:
Expand All @@ -509,12 +513,16 @@ def walk_node_list_less_note_contents(node_list):
if isinstance(obj, list):
yield from walk_node_list_less_note_contents(obj)
elif isinstance(obj, dict):
try:
node_type = obj['t']
except KeyError:
continue
yield (obj, node_list, index)
if obj['t'] == 'Note':
if node_type == 'Note':
continue
obj_contents = obj.get('c', None)
if isinstance(obj_contents, list):
if obj['t'] != 'DefinitionList':
if node_type != 'DefinitionList':
yield from walk_node_list_less_note_contents(obj_contents)
else:
for elem in obj_contents:
Expand Down
2 changes: 1 addition & 1 deletion codebraid/version.py
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-

from .fmtversion import get_version_plus_info
__version__, __version_info__ = get_version_plus_info(0, 5, 0, 'dev', 0)
__version__, __version_info__ = get_version_plus_info(0, 5, 0, 'dev', 1)

0 comments on commit 911e103

Please sign in to comment.