Escape string to HTML

When keep_entities, HTML entities will not be escaped.

Property definitions

markdown2 $ HtmlRenderer :: html_escape
	# Escape `string` to HTML
	#
	# When `keep_entities`, HTML entities will not be escaped.
	fun html_escape(string: String, keep_entities: Bool): String do
		var buf: nullable Buffer = null
		for i in [0..string.length[ do
			var c = string.chars[i]
			var sub = null
			if c == '&' and (not keep_entities or string.search_from(re_entity, i) == null) then
				sub = "&"
			else if c == '<' then
				sub = "&lt;"
			else if c == '>' then
				sub = "&gt;"
			else if c == '"' then
				sub = "&quot;"
			else
				if buf != null then buf.add c
				continue
			end
			if buf == null then
				buf = new Buffer
				for j in [0..i[ do buf.add string.chars[j]
			end
			buf.append sub
		end

		if buf == null then return string
		return buf.to_s
	end
lib/markdown2/markdown_html_rendering.nit:74,2--103,4