From 454164fa78bab1cf651a0ea5868542a66c052a09 Mon Sep 17 00:00:00 2001 From: Michele Carignani <michele.carignani@etsi.org> Date: Mon, 30 Nov 2020 19:10:28 +0100 Subject: [PATCH] support tables for examples in Annex A --- src/example.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/example.py b/src/example.py index 971ccc9..8649606 100644 --- a/src/example.py +++ b/src/example.py @@ -6,6 +6,7 @@ import re import traceback from docx.text.paragraph import Paragraph +from docx.table import Table class Example(): @@ -50,6 +51,9 @@ def is_heading(txt :str): ''' return txt.startswith("A.") +def is_example_table(tab): + return len(tab.rows) == 1 and len(tab.rows[0].cells) == 1 + def parse_all_examples(txt): ''' Parses TOSCA examples. Txt is a list of Docx items (Paragraph, etc.). @@ -67,6 +71,9 @@ def parse_all_examples(txt): if is_heading(linetext): clause = linetext.split("\t")[0] i = 1 + elif isinstance(line, Table): + if is_example_table(line): + linetext = str(line.rows[0].cells[0].text) elif isinstance(line, str): linetext = line else: -- GitLab