From f8f566396251825ac2b73be5e75b419c35f5e0ec Mon Sep 17 00:00:00 2001 From: Adang23 <122211611+Adang23@users.noreply.github.com> Date: Fri, 29 Sep 2023 08:33:10 -0400 Subject: [PATCH] Create xml.lua --- lua/custom/plugins/xml.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 lua/custom/plugins/xml.lua diff --git a/lua/custom/plugins/xml.lua b/lua/custom/plugins/xml.lua new file mode 100644 index 00000000..8a874536 --- /dev/null +++ b/lua/custom/plugins/xml.lua @@ -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 {}