Read self as XML and append it to the out buffer.

Safe mode can be activated to limit reading to valid xml.

Property definitions

markdown :: markdown $ Text :: read_xml
	# Read `self` as XML and append it to the `out` buffer.
	# Safe mode can be activated to limit reading to valid xml.
	private fun read_xml(out: FlatBuffer, start: Int, safe_mode: Bool): Int do
		var pos = 0
		var is_valid = true
		var is_close_tag = false
		if start + 1 >= length then return -1
		if self[start + 1] == '/' then
			is_close_tag = true
			pos = start + 2
		else if self[start + 1] == '!' then
			out.append "<!"
			return start + 1
		else
			is_close_tag = false
			pos = start + 1
		end
		if safe_mode then
			var tmp = new FlatBuffer
			pos = read_xml_until(tmp, pos, ' ', '/', '>')
			if pos == -1 then return -1
			var tag = tmp.write_to_string.trim.to_lower
			if not tag.is_valid_html_tag then
				out.append "&lt;"
				pos = -1
			else if tag.is_html_unsafe then
				is_valid = false
				out.append "&lt;"
				if is_close_tag then out.add '/'
				out.append tmp
			else
				out.append "<"
				if is_close_tag then out.add '/'
				out.append tmp
			end
		else
			out.add '<'
			if is_close_tag then out.add '/'
			pos = read_xml_until(out, pos, ' ', '/', '>')
		end
		if pos == -1 then return -1
		pos = read_xml_until(out, pos, '/', '>')
		if pos == -1 then return -1
		if self[pos] == '/' then
			out.append " /"
			pos = self.read_xml_until(out, pos + 1, '>')
			if pos == -1 then return -1
		end
		if self[pos] == '>' then
			if is_valid then
				out.add '>'
			else
				out.append "&gt;"
			end
			return pos
		end
		return -1
	end
lib/markdown/markdown.nit:2430,2--2487,4