XML reformating

From: <briancsch....at.gmail.com>
Date: Wed, 2 Jun 2010 11:50:55 -0700 (PDT)

Here's a function for re-formatting XML. Requires some sort of echo
command and HTML tidy to be installed and placed on your system's
PATH. Not tested on anything but Linux.

local function reformat()
        local tidyString = 'tidy -i -xml -q -w '..buffer.edge_column
                ..' --indent-spaces '..buffer.indent..' --tab-size
'..buffer.tab_width
        local text = buffer:get_text():gsub('"', '\\"')
        local p = io.popen('echo "'..text..'" | '..tidyString..' 2>&1')
        local out = p:read('*all')
        p:close()
        if buffer.use_tabs then
                out = out:gsub(string.rep(" ", buffer.indent), "\t")
        end
        buffer:set_text(out)
Received on Wed 02 Jun 2010 - 14:50:55 EDT

This archive was generated by hypermail 2.2.0 : Thu 08 Mar 2012 - 11:46:51 EST