Added proper handling of headers with bold, italic or emphasis

Signed-off-by: Maksym Lysak <mly@zurich.ibm.com>
This commit is contained in:
Maksym Lysak 2024-10-25 10:39:07 +02:00
parent 1c933e20f8
commit 97999ebb43

View File

@ -135,8 +135,21 @@ class MarkdownDocumentBackend(DeclarativeDocumentBackend):
doc_label = DocItemLabel.TITLE
else:
doc_label = DocItemLabel.SECTION_HEADER
snippet_text = element.children[0].children.strip()
if isinstance(element.children[0].children, str):
# Straight text in the header
snippet_text = element.children[0].children.strip()
elif isinstance(element.children[0].children[0].children, str):
# Bold or italic text in the header
snippet_text = element.children[0].children[0].children.strip()
elif isinstance(element.children[0].children[0].children[0].children, str):
# Emphasized text in the header
snippet_text = (
element.children[0].children[0].children[0].children.strip()
)
print("snippet_text: {}".format(snippet_text))
if len(snippet_text) > 0:
parent_element = doc.add_text(
label=doc_label, parent=parent_element, text=snippet_text
)