Skip to content

Commit

Permalink
Test and fix minor issues in USJ generation
Browse files Browse the repository at this point in the history
  • Loading branch information
kavitharaju committed Sep 28, 2023
1 parent 028d6a7 commit e0fec41
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions py-usfm-parser/src/usfm_grammar/usj_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ def node_2_usj_para(self, node, parent_json_obj):
para_tag_cap = self.usfm_language.query(
"(paragraph (_) @para-marker)").captures(node)[0]
para_marker = para_tag_cap[0].type
if not para_marker.endswith("Block"):
if para_marker == "b":
self.node_2_usj_special(para_tag_cap[0], parent_json_obj)
elif not para_marker.endswith("Block"):
para_json_obj = {"type": f"para:{para_marker}", "content":[]}
for child in para_tag_cap[0].children[1:]:
self.node_2_usj(child, para_json_obj)
Expand Down Expand Up @@ -288,14 +290,14 @@ def node_2_usj_generic(self, node, parent_json_obj):
style += num
children_range_start = 2
para_json_obj = {"type": f"para:{style}", "content":[]}
parent_json_obj['content'].append(para_json_obj)
for child in node.children[children_range_start:]:
if child.type in self.CHAR_STYLE_MARKERS+self.NESTED_CHAR_STYLE_MARKERS+\
["text", "footnote", "crossref", "verseText", "v", "b", "milestone", "zNameSpace"]:
# only nest these types inside the upper para style node
self.node_2_usj(child, para_json_obj)
else:
self.node_2_usj(child, parent_json_obj)
parent_json_obj['content'].append(para_json_obj)

def node_2_usj(self, node, parent_json_obj): # pylint: disable= too-many-branches
'''check each node and based on the type convert to corresponding xml element'''
Expand Down Expand Up @@ -323,14 +325,15 @@ def node_2_usj(self, node, parent_json_obj): # pylint: disable= too-many-branche
self.node_2_usj_attrib(node, parent_json_obj)
elif node.type == 'text':
text_val = self.usfm[node.start_byte:node.end_byte].decode('utf-8').strip()
parent_json_obj['content'].append(text_val)
if text_val != "":
parent_json_obj['content'].append(text_val)
elif node.type in ["table", "tr"]+ self.TABLE_CELL_MARKERS:
self.node_2_usj_table(node, parent_json_obj)
elif node.type == "milestone":
self.node_2_usj_milestone(node, parent_json_obj)
elif node.type == "zNameSpace":
self.node_2_usj_milestone(node, parent_json_obj)
elif node.type in ["esb", "cat", "fig", "b", "usfm"]:
elif node.type in ["esb", "cat", "fig", "usfm"]:
self.node_2_usj_special(node, parent_json_obj)
elif (node.type in self.PARA_STYLE_MARKERS or
node.type.replace("\\","").strip() in self.PARA_STYLE_MARKERS):
Expand Down

0 comments on commit e0fec41

Please sign in to comment.