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

Escape HTML special chars.

Property definitions

markdown :: markdown $ Text :: read_xml_until
	# Read `self` as XML until `to` and append it to the `out` buffer.
	# Escape HTML special chars.
	private fun read_xml_until(out: FlatBuffer, from: Int, to: Char...): Int do
		var pos = from
		var in_str = false
		var str_char: nullable Char = null
		while pos < length do
			var c = self[pos]
			if in_str then
				if c == '\\' then
					out.add c
					pos += 1
					if pos < length then
						out.add c
						pos += 1
					end
					continue
				end
				if c == str_char then
					in_str = false
					out.add c
					pos += 1
					continue
				end
			end
			if c == '"' or c == '\'' then
				in_str = true
				str_char = c
			end
			if not in_str then
				var end_reached = false
				for n in [0..to.length[ do
					if c == to[n] then
						end_reached = true
						break
					end
				end
				if end_reached then break
			end
			out.add c
			pos += 1
		end
		if pos == length then return -1
		return pos
	end
lib/markdown/markdown.nit:2384,2--2428,4