-- lx format
local format = require("core.format")

format.register({
	name = "Extensible Markup (XML)",
	shortname = "XML",
	author = "liqube",
	extensions = {
		"xml",
		"xslt",
	},
	headers = "<%?xml",

	patterns = {
		{ pattern = "<%?xml%s?[^\n>]*>", type = "meta", caseless = true },
		{ pattern = "<%/xml>", type = "meta", caseless = true },

		{ pattern = { "<!%-%-", "%-%->" }, type = "comment" },
		-- Pattern breakdown: frontier requires the previous character to be '>'; [^<]+ consumes text through the next '<'
		{ pattern = "%f[^>][^<]+", type = "normal" },
		-- XML quotes open attribute values only after '='; apostrophes in element text stay plain
		{ pattern = { '"', '"' }, type = "string", preceded_by = "=%s*" },
		{ pattern = { "'", "'" }, type = "string", preceded_by = "=%s*" },

		{ pattern = "0x[%da-fA-F]+", type = "hex" },
		{ pattern = "-?%d+[%d%.]*f?", type = "number" },
		{ pattern = "-?%.?%d+f?", type = "number" },

		{ pattern = "%f[^<]![%a_][%w_]*", type = "keyword2" },
		{ pattern = "%f[^<][%a_][%w_]*", type = "function" },
		{ pattern = "%f[^<]/[%a_][%w_]*", type = "function" },
		{ pattern = "[%a_][%w_]*", type = "keyword" },
		{ pattern = "[/<>=]", type = "operator" },
	},

	block_comment = {
		block_open = "<!--",
		block_close = "-->",
		block_line_prefix = "",
		close_line_prefix = "",
		open_on_own_line = false,
		close_on_own_line = false,
		strip_line_prefix = "",
	},
})
