import pn import scintilla import re, string from pypn.decorators import script @script("Beautify", "Xml") def Beautify(): editor = scintilla.Scintilla(pn.CurrentDoc()) data = editor.GetText(editor.Length) fields = re.split('(<.*?>)',data) content = '' level = 0 for f in fields: if string.strip(f)=='': continue if f[0]=='<' and f[1] != '/' and f[-2] != '/': content += ' '*(level*4) + f + '\n' level = level + 1 elif f[0] == '<' and f[1] != '/' and f[-2] == '/': content += ' '*(level*4) + f + '\n' elif f[:2]=='