input
string as a MdDocument
# Parse the `input` string as a MdDocument
fun parse(input: String): MdDocument do
initialize
var document_block_parser = new MdDocumentBlockParser(1, 1, 0)
activate_block_parser(document_block_parser)
var line_start = 0
var line_break = find_line_break(input, line_start)
while line_break != -1 do
var line_string = input.substring(line_start, line_break - line_start)
incorporate_line(line_string)
if line_break + 1 < input.length and
input.chars[line_break] == '\r' and
input.chars[line_break + 1] == '\n' then
line_start = line_break + 2
else
line_start = line_break + 1
end
line_break = find_line_break(input, line_start)
line += 1
column = 0
end
# Finalize pending line
if input.length > 0 and (line_start == 0 or line_start < input.length) then
incorporate_line(input.substring(line_start, input.length - line_start))
end
finalize_blocks(active_block_parsers)
# Walk through a block and its chiildren revursively
# Parsing string content into inline content where appropriate.
var all_block_parsers = all_block_parsers.to_a
var i = all_block_parsers.length - 1
while i >= 0 do
var block_parser = all_block_parsers[i]
block_parser.parse_inlines(inline_parser)
i -= 1
end
var document = document_block_parser.block
return document
end
lib/markdown2/markdown_block_parsing.nit:133,2--173,4