diff --git a/docx/oxml/text.py b/docx/oxml/text.py index fbcf6974f..47b335aca 100644 --- a/docx/oxml/text.py +++ b/docx/oxml/text.py @@ -59,6 +59,13 @@ def get_or_add_pPr(self): if pPr is None: pPr = self._add_pPr() return pPr + + def clear_r(self): + """ + Remove all run elements in this paragraph. + """ + for r in self.r_lst: + self.remove(r) @staticmethod def new(): @@ -253,6 +260,13 @@ def get_or_add_rPr(self): rPr = self._add_rPr() return rPr + def clear_t(self): + """ + Remove all text elements in this run. + """ + for t in self.t_lst: + self.remove(t) + @classmethod def new(cls): """ diff --git a/docx/text.py b/docx/text.py index 3d9c648ad..5491d1656 100644 --- a/docx/text.py +++ b/docx/text.py @@ -67,6 +67,12 @@ def add_run(self, text=None): if text: run.add_text(text) return run + + def clear_runs(self): + """ + Remove all runs in this paragraph. + """ + self._p.clear_r() @property def runs(self): @@ -140,6 +146,12 @@ def add_text(self, text): t = self._r.add_t(text) return Text(t) + def clear_texts(self): + """ + Remove all text in this run. + """ + self._r.clear_t() + @boolproperty def all_caps(self): """