Skip to content
Snippets Groups Projects
Commit 5f66c8f0 authored by David Rouquet's avatar David Rouquet
Browse files

Add text identifier (num) to notebook cells

parent 082f2a97
Branches
No related tags found
No related merge requests found
Pipeline #239 passed
...@@ -26,12 +26,13 @@ def unlizeXmlNb(input, output, template, lang, dry_run): ...@@ -26,12 +26,13 @@ def unlizeXmlNb(input, output, template, lang, dry_run):
tags = ['title', 'text_body', 'term', 'meaning'] tags = ['title', 'text_body', 'term', 'meaning']
for t in tags: for t in tags:
for node in doc.xpath('//'+t): for node in doc.xpath('//'+t):
num = str(node.xpath('../@id')[0])
if node.text: if node.text:
# Add # Add
unl = unlize(nestedBody2Str(node), lang, dry_run) unl = unlize(nestedBody2Str(node), lang, dry_run)
addCell(nb, unl) addCell(nb, unl, num)
else: else:
addCell(nb, getText(node, 'unl')) addCell(nb, getText(node, 'unl'), num)
# We execute the notebook # We execute the notebook
#resources = {} #resources = {}
#exec_nb, resources = ExecutePreprocessor(timeout=-1).preprocess(nb, resources) #exec_nb, resources = ExecutePreprocessor(timeout=-1).preprocess(nb, resources)
...@@ -45,11 +46,12 @@ def getText(node, tag): ...@@ -45,11 +46,12 @@ def getText(node, tag):
except IndexError: except IndexError:
return '' return ''
def addCell(nb, unl): def addCell(nb, unl, num=''):
code = """unldata = \"\"\" code = """num = \"{num}\"
unldata = \"\"\"
{unl} {unl}
\"\"\" \"\"\"
displayUnl(unldata)""".format(unl=unl.strip()) displayUnl(unldata)""".format(num=num,unl=unl.strip())
nb['cells'].append(new_code_cell(code)) nb['cells'].append(new_code_cell(code))
if __name__ == '__main__': if __name__ == '__main__':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment