# Check if the link is a valid link.
private fun check_link(v: MarkdownProcessor, out: FlatBuffer, start: Int, token: Token): Int do
var md = v.current_text
if md == null then return -1
var pos
if token isa TokenLink then
pos = start + 1
else
pos = start + 2
end
var tmp = new FlatBuffer
pos = md.read_md_link_id(tmp, pos)
if pos < start then return -1
name = tmp
var old_pos = pos
pos += 1
pos = md.skip_spaces(pos)
if pos < start then
var tid = name.as(not null).write_to_string.to_lower
if v.link_refs.has_key(tid) then
var lr = v.link_refs[tid]
is_abbrev = lr.is_abbrev
link = lr.link
comment = lr.title
pos = old_pos
else
return -1
end
else if md[pos] == '(' then
pos += 1
pos = md.skip_spaces(pos)
if pos < start then return -1
tmp = new FlatBuffer
var use_lt = md[pos] == '<'
if use_lt then
pos = md.read_until(tmp, pos + 1, '>')
else
pos = md.read_md_link(tmp, pos)
end
if pos < start then return -1
if use_lt then pos += 1
link = tmp.write_to_string
if md[pos] == ' ' then
pos = md.skip_spaces(pos)
if pos > start and md[pos] == '"' then
pos += 1
tmp = new FlatBuffer
pos = md.read_until(tmp, pos, '"')
if pos < start then return -1
comment = tmp.write_to_string
pos += 1
pos = md.skip_spaces(pos)
if pos == -1 then return -1
end
end
if pos < start then return -1
if md[pos] != ')' then return -1
else if md[pos] == '[' then
pos += 1
tmp = new FlatBuffer
pos = md.read_raw_until(tmp, pos, ']')
if pos < start then return -1
var id
if tmp.length > 0 then
id = tmp
else
id = name
end
var tid = id.as(not null).write_to_string.to_lower
if v.link_refs.has_key(tid) then
var lr = v.link_refs[tid]
link = lr.link
comment = lr.title
end
else
var tid = name.as(not null).write_to_string.replace("\n", " ").to_lower
if v.link_refs.has_key(tid) then
var lr = v.link_refs[tid]
link = lr.link
comment = lr.title
pos = old_pos
else
return -1
end
end
if link == null then return -1
return pos
end
lib/markdown/markdown.nit:2100,2--2187,4
redef fun check_link(v, out, start, token) do
var md = v.current_text
if md == null then return -1
var pos = start + 2
var tmp = new FlatBuffer
pos = md.read_md_link_id(tmp, pos)
if pos < start then return -1
var name = tmp.write_to_string
if name.has("|") then
var parts = name.split_once_on("|")
self.name = parts.first
self.link = parts[1]
else
self.name = null
self.link = name
end
pos += 1
pos = md.skip_spaces(pos)
if pos < start then return -1
return pos
end
lib/markdown/wikilinks.nit:73,2--93,4