# Paragraphs parser
class MdParagraphParser
super MdBlockParser
redef type BLOCK: MdParagraph
redef var block = new MdParagraph(location) is lazy
# Paragraph content
var content: nullable Buffer = new Buffer
redef fun try_continue(state) do
if state.is_blank then return null
return new MdBlockContinue.at_index(state.index)
end
redef fun add_line(line) do
var content = self.content
if content == null then return
if not content.is_empty then
content.add('\n')
end
content.append(line)
end
redef fun finalize(parser) do
super
var inline_parser = parser.inline_parser
var content = self.content
if content == null then return
var content_string = content.to_s
var has_reference_defs = false
var pos = inline_parser.parse_reference(content_string)
# try parsing the beginning as link reference definitions
while content_string.length > 3 and content_string.chars[0] == '[' and pos != 0 do
content_string = content_string.substring(pos, content_string.length - pos)
has_reference_defs = true
pos = inline_parser.parse_reference(content_string)
end
if has_reference_defs and content_string.is_blank then
block.unlink
self.content = null
else
self.content = new Buffer.from_text(content_string)
end
end
redef fun parse_inlines(inline_parser) do
var content = self.content
if content == null then return
inline_parser.parse(content.to_s, content_offset, block)
var last_child = block.last_child
if last_child != null then
location.line_end = last_child.location.line_end
location.column_end = last_child.location.column_end
end
end
end
lib/markdown2/markdown_block_parsing.nit:1220,1--1282,3