Return true
if line contains a valid link ref and save it into link_refs
.
# Check if line is a block link definition.
# Return `true` if line contains a valid link ref and save it into `link_refs`.
private fun check_link_ref(line: MDLine): Bool do
var md = line.value
var is_link_ref = false
var id = new FlatBuffer
var link = new FlatBuffer
var comment = new FlatBuffer
var pos = -1
if not line.is_empty and line.leading < 4 and line.value[line.leading] == '[' then
pos = line.leading + 1
pos = md.read_until(id, pos, ']')
if not id.is_empty and pos >= 0 and pos + 2 < line.value.length then
if line.value[pos + 1] == ':' then
pos += 2
pos = md.skip_spaces(pos)
if pos >= 0 and line.value[pos] == '<' then
pos += 1
pos = md.read_until(link, pos, '>')
pos += 1
else if pos >= 0 then
pos = md.read_until(link, pos, ' ', '\n')
end
if not link.is_empty then
pos = md.skip_spaces(pos)
if pos > 0 and pos < line.value.length then
var c = line.value[pos]
if c == '\"' or c == '\'' or c == '(' then
pos += 1
if c == '(' then
pos = md.read_until(comment, pos, ')')
else
pos = md.read_until(comment, pos, c)
end
if pos > 0 then is_link_ref = true
end
else
is_link_ref = true
end
end
end
end
end
if is_link_ref and not id.is_empty and not link.is_empty then
var lr = new LinkRef.with_title(link.write_to_string, comment.write_to_string)
add_link_ref(id.write_to_string, lr)
if comment.is_empty then last_link_ref = lr
return true
else
comment = new FlatBuffer
if not line.is_empty and last_link_ref != null then
pos = line.leading
var c = line.value[pos]
if c == '\"' or c == '\'' or c == '(' then
pos += 1
if c == '(' then
pos = md.read_until(comment, pos, ')')
else
pos = md.read_until(comment, pos, c)
end
end
var last_link_ref = self.last_link_ref
if not comment.is_empty and last_link_ref != null then
last_link_ref.title = comment.write_to_string
end
end
if comment.is_empty then return false
return true
end
end
lib/markdown/markdown.nit:200,2--269,4