Create xml.lua

This commit is contained in:
Adang23 2023-09-29 08:33:10 -04:00 committed by GitHub
parent bf0db95c19
commit f8f5663962
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 0 deletions

View File

@ -0,0 +1,23 @@
local function setup_format_xml_command()
local python_code = [[
import vim
import xml.dom.minidom
def format_xml():
buf = vim.current.buffer
xml_data = '\n'.join(buf)
dom = xml.dom.minidom.parseString(xml_data)
pretty_xml = dom.toprettyxml()
formatted_lines = pretty_xml.split('\n')
buf[:] = formatted_lines
format_xml()
]]
vim.api.nvim_command("command! FormatXML :py3 " .. python_code)
end
-- Call the function to set up the command
setup_format_xml_command()
return {}