Property definitions

markdown $ TokenEntity :: defaultinit
# An HTML entity token.
class TokenEntity
	super Token

	redef fun emit(v) do
		var tmp = new FlatBuffer
		var b = check_entity(tmp, v.current_text.as(not null), pos)
		if b > 0 then
			v.add tmp
			v.current_pos = b
		else
			v.decorator.escape_char(v, char)
		end
	end

	# Is the entity valid?
	private fun check_entity(out: FlatBuffer, md: Text, start: Int): Int do
		var pos = md.read_until(out, start, ';')
		if pos < 0 or out.length < 3 then
			return -1
		end
		if out[1] == '#' then
			if out[2] == 'x' or out[2] == 'X' then
				if out.length < 4 then return -1
				for i in [3..out.length[ do
					var c = out[i]
					if (c < '0' or c > '9') and (c < 'a' and c > 'f') and (c < 'A' and c > 'F') then
						return -1
					end
				end
			else
				for i in [2..out.length[ do
					var c = out[i]
					if c < '0' or c > '9' then return -1
				end
			end
			out.add ';'
		else
			for i in [1..out.length[ do
				var c = out[i]
				if not c.is_digit and not c.is_letter then return -1
			end
			out.add ';'
			# TODO check entity is valid
			# if out.is_entity then
				return pos
			# else
				# return -1
			# end
		end
		return pos
	end
end
lib/markdown/markdown.nit:2250,1--2302,3