From 6b0f2fd1e3c39c9dc2494de58aa84370674d1455 Mon Sep 17 00:00:00 2001 From: Jean-Francois Thuong Date: Wed, 23 Oct 2019 15:23:22 +0800 Subject: [PATCH] Added paragraph property to get text after changes Added paragraph property `Paragraph.accepted_text` to get text after accepting changes (insertion and deletion). --- docx/text/paragraph.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docx/text/paragraph.py b/docx/text/paragraph.py index 4fb583b94..43a93c68b 100644 --- a/docx/text/paragraph.py +++ b/docx/text/paragraph.py @@ -136,6 +136,19 @@ def text(self, text): self.clear() self.add_run(text) + @property + def accepted_text(self): + """ + String formed by accepting all changes and concatenating + the text of each run in the paragraph. + Tabs and line breaks in the XML are mapped to ``\\t`` and ``\\n`` + characters respectively. + """ + text = '' + for run_text in self._p.xpath(".//w:t"): + text += run_text.text + return text + def _insert_paragraph_before(self): """ Return a newly created paragraph, inserted directly before this