Skip to content

Commit

Permalink
xml header processing, closes #8
Browse files Browse the repository at this point in the history
  • Loading branch information
alek-sys committed Nov 24, 2011
1 parent 8d5a5d8 commit 78da832
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions indentxml.py
Expand Up @@ -37,9 +37,10 @@ def run(self, edit):
s = self.indentxml(s)
view.replace(edit, alltextreg, s)

def indentxml(self, s):
def indentxml(self, s):
# convert to utf
s = s.encode("utf-8")
s = s.encode("utf-8")
xmlheader = re.compile("<\?.*\?>").match(s)
# convert to plain string without indents and spaces
s = re.compile('>\s+([^\s])', re.DOTALL).sub('>\g<1>', s)
# replace tags to convince minidom process cdata as text
Expand All @@ -51,4 +52,6 @@ def indentxml(self, s):
s = s.replace('%CDATAESTART%', '<![CDATA[').replace('%CDATAEEND%', ']]>')
# remove xml header
s = s.replace("<?xml version=\"1.0\" ?>", "").strip()
if xmlheader:
s = xmlheader.group() + "\n" + s
return s

0 comments on commit 78da832

Please sign in to comment.