From 5f66c8f043378c1917f2c2f245564b377264eb81 Mon Sep 17 00:00:00 2001
From: David Rouquet <david.rouquet@tetras-libre.fr>
Date: Wed, 6 Jan 2021 19:25:00 +0100
Subject: [PATCH] Add text identifier (num) to notebook cells

---
 scripts/unlizeToNotebook.py | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/scripts/unlizeToNotebook.py b/scripts/unlizeToNotebook.py
index df30aff..584b9ce 100755
--- a/scripts/unlizeToNotebook.py
+++ b/scripts/unlizeToNotebook.py
@@ -26,12 +26,13 @@ def unlizeXmlNb(input, output, template, lang, dry_run):
     tags = ['title', 'text_body', 'term', 'meaning']
     for t in tags:
         for node in doc.xpath('//'+t):
+            num = str(node.xpath('../@id')[0])
             if node.text:
                 # Add
                 unl = unlize(nestedBody2Str(node), lang, dry_run)
-                addCell(nb, unl)
+                addCell(nb, unl, num)
             else:
-                addCell(nb, getText(node, 'unl'))
+                addCell(nb, getText(node, 'unl'), num)
     # We execute the notebook
     #resources = {}
     #exec_nb, resources = ExecutePreprocessor(timeout=-1).preprocess(nb, resources)
@@ -45,11 +46,12 @@ def getText(node, tag):
     except IndexError:
         return ''
 
-def addCell(nb, unl):
-    code = """unldata = \"\"\"
+def addCell(nb, unl, num=''):
+    code = """num = \"{num}\"
+    unldata = \"\"\"
 {unl}
 \"\"\"
-displayUnl(unldata)""".format(unl=unl.strip())
+displayUnl(unldata)""".format(num=num,unl=unl.strip())
     nb['cells'].append(new_code_cell(code))
 
 if __name__ == '__main__':
-- 
GitLab