This class is mainly used to factorize work between images and links.
markdown :: TokenLinkOrImage :: is_abbrev
Is the link construct an abbreviation?markdown :: TokenLinkOrImage :: is_abbrev=
Is the link construct an abbreviation?markdown $ TokenLinkOrImage :: SELF
Type of this instance, automatically specialized in every classmarkdown $ TokenLinkOrImage :: emit
Output that token usingMarkdownEmitter::decorator
.
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
markdown :: Token :: defaultinit
core :: Object :: defaultinit
MarkdownEmitter::decorator
.
markdown :: TokenLinkOrImage :: is_abbrev
Is the link construct an abbreviation?markdown :: TokenLinkOrImage :: is_abbrev=
Is the link construct an abbreviation?core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
self
in the original input.
markdown :: Token :: location=
Location ofself
in the original input.
core :: Object :: output_class_name
Display class name on stdout (debug only).
# A link or image token.
# This class is mainly used to factorize work between images and links.
abstract class TokenLinkOrImage
super Token
# Link adress
var link: nullable Text = null
# Link text
var name: nullable Text = null
# Link title
var comment: nullable Text = null
# Is the link construct an abbreviation?
var is_abbrev = false
redef fun emit(v) do
var tmp = new FlatBuffer
var b = check_link(v, tmp, pos, self)
if b > 0 then
emit_hyper(v)
v.current_pos = b
else
v.addc char
end
end
# Emit the hyperlink as link or image.
private fun emit_hyper(v: MarkdownProcessor) is abstract
# 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
end
lib/markdown/markdown.nit:2069,1--2188,3