From 2070dcba43ab3e463818599924f78a395f823543 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Sun, 31 Jul 2005 04:43:06 +0000 Subject: [PATCH] * src/docgen/OpenOfficeDoc.org: remove ^L and ^Z from output, use xml.sax.saxutils.escape to handle XML entities svn: r4984 --- gramps2/ChangeLog | 3 ++- gramps2/src/docgen/OpenOfficeDoc.py | 26 +++++++++++++++----------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 7b1b56076..e525a8f3f 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,5 +1,6 @@ 2005-07-30 Don Allingham - * src/docgen/OpenOfficeDoc.org: remove ^L and ^Z from output + * src/docgen/OpenOfficeDoc.org: remove ^L and ^Z from output, use + xml.sax.saxutils.escape to handle XML entities 2005-07-29 Don Allingham * src/GrampsBSDDB.py: issue complete redraw on name grouping change diff --git a/gramps2/src/docgen/OpenOfficeDoc.py b/gramps2/src/docgen/OpenOfficeDoc.py index 9f34d23ad..0fc2535ba 100644 --- a/gramps2/src/docgen/OpenOfficeDoc.py +++ b/gramps2/src/docgen/OpenOfficeDoc.py @@ -52,10 +52,18 @@ from ReportUtils import pt2cm # #------------------------------------------------------------------------- from gettext import gettext as _ - +from xml.sax.saxutils import escape _apptype = 'application/vnd.sun.xml.writer' +_esc_map = { + '\x1a' : '', + '\x0c' : '', + '\n' : '', + '<super>' : '', + '</super>' : '') + } + #------------------------------------------------------------------------- # # OpenOfficeDoc @@ -704,16 +712,12 @@ class OpenOfficeDoc(BaseDoc.BaseDoc): self.end_paragraph() def write_text(self,text): - text = text.replace('&','&') # Must be first - text = text.replace('<','<') - text = text.replace('>','>') - text = text.replace('\x1a','') - text = text.replace('\x0c','') - text = text.replace('\n','') - text = text.replace('<super>', - '') - text = text.replace('</super>','') - self.cntnt.write(text) + """ + Uses the xml.sax.saxutils.escape function to convert XML + entities. The _esc_map dictionary allows us to add our own + mappings. + """ + self.cntnt.write(escape(text,_esc_map)) def _write_manifest(self): self.mfile = StringIO()