From 05d9ac1031dcf83c6d99fa2218ee45a6d7b4d746 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 3 Jul 2016 12:16:50 +0100 Subject: Add reader for comments.xml --- mammoth/documents.py | 7 +++++++ mammoth/docx/comments_xml.py | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 mammoth/docx/comments_xml.py (limited to 'mammoth') diff --git a/mammoth/documents.py b/mammoth/documents.py index 36e3458..ea376d4 100644 --- a/mammoth/documents.py +++ b/mammoth/documents.py @@ -173,4 +173,11 @@ class NoteReference(Element): note_reference = NoteReference +@cobble.data +class Comment(object): + comment_id = cobble.field() + body = cobble.field() + +comment = Comment + ElementVisitor = cobble.visitor(Element) diff --git a/mammoth/docx/comments_xml.py b/mammoth/docx/comments_xml.py new file mode 100644 index 0000000..9a92552 --- /dev/null +++ b/mammoth/docx/comments_xml.py @@ -0,0 +1,19 @@ +from .. import lists +from .. import documents +from .. import results + + +def create_comments_reader(body_reader): + def read_comments_xml_element(element): + comment_elements = element.find_children("w:comment") + return results.combine(lists.map(_read_comment_element, comment_elements)) + + + def _read_comment_element(element): + return body_reader.read_all(element.children).map(lambda body: + documents.comment( + comment_id=element.attributes["w:id"], + body=body + )) + + return read_comments_xml_element -- cgit v1.2.3