Skip to content

Commit f25abcf

Browse files
committed
Debug disabled. New function 'clean'
1 parent 19c1331 commit f25abcf

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

docx.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,25 @@ def replace(document,search,replace):
479479
element.text = re.sub(search,replace,element.text)
480480
return newdocument
481481

482+
def clean(document):
483+
""" Perform misc cleaning operations on documents.
484+
Returns cleaned document.
485+
"""
486+
487+
newdocument = document
488+
489+
# Clean empty text and r tags
490+
for t in ('t', 'r'):
491+
rmlist = []
492+
for element in newdocument.iter():
493+
if element.tag == '{%s}%s' % (nsprefixes['w'], t):
494+
if not element.text and not len(element):
495+
rmlist.append(element)
496+
for element in rmlist:
497+
element.getparent().remove(element)
498+
499+
return newdocument
500+
482501
def advReplace(document,search,replace,bs=3):
483502
'''Replace all occurences of string with a different string, return updated document
484503
@@ -518,7 +537,7 @@ def advReplace(document,search,replace,bs=3):
518537
519538
'''
520539
# Enables debug output
521-
DEBUG = True
540+
DEBUG = False
522541

523542
newdocument = document
524543

0 commit comments

Comments
 (0)