From bc62c8382815d5ca3b0812247cbc46ba8430ebab Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 1 Dec 2013 13:34:41 +0000 Subject: Read bold property of runs --- mammoth/documents.py | 6 +++--- mammoth/docx/document_xml.py | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'mammoth') diff --git a/mammoth/documents.py b/mammoth/documents.py index 215df8e..03975b2 100644 --- a/mammoth/documents.py +++ b/mammoth/documents.py @@ -2,7 +2,7 @@ import collections Document = collections.namedtuple("Document", ["children"]) Paragraph = collections.namedtuple("Paragraph", ["children", "style_name", "numbering"]) -Run = collections.namedtuple("Run", ["children", "style_name"]) +Run = collections.namedtuple("Run", ["children", "style_name", "is_bold"]) Text = collections.namedtuple("Text", ["value"]) @@ -11,7 +11,7 @@ document = Document def paragraph(children, style_name=None, numbering=None): return Paragraph(children, style_name, numbering) -def run(children, style_name=None): - return Run(children, style_name) +def run(children, style_name=None, is_bold=None): + return Run(children, style_name, bool(is_bold)) text = Text diff --git a/mammoth/docx/document_xml.py b/mammoth/docx/document_xml.py index c3fb1b7..6488a25 100644 --- a/mammoth/docx/document_xml.py +++ b/mammoth/docx/document_xml.py @@ -26,7 +26,13 @@ def _create_reader(numbering): style_name = properties \ .find_child_or_null("w:rStyle") \ .attributes.get("w:val") - return documents.run(_read_xml_elements(element.children), style_name) + is_bold = properties.find_child("w:b") + + return documents.run( + children=_read_xml_elements(element.children), + style_name=style_name, + is_bold=is_bold, + ) @handler("w:p") -- cgit v1.2.3