Enables parsing of [[wikilinks]]
syntax.
markdown2 :: markdown_wikilinks $ MdInlineParser
Parser for inline content (text, links, emphasis, etc)markdown2 :: markdown_wikilinks $ MdInlineParser
Parser for inline content (text, links, emphasis, etc)core :: union_find
union–find algorithm using an efficient disjoint-set data structuremarkdown2 :: markdown_html_rendering
HTML rendering of Markdown documentsmarkdown2 :: markdown_latex_rendering
LaTeX rendering of Markdown documentsmarkdown2 :: markdown_man_rendering
Manpages rendering of Markdown documentsmarkdown2 :: markdown_md_rendering
Markdown rendering of Markdown documents
# Markdown wikilinks processing
#
# Enables parsing of `[[wikilinks]]` syntax.
module markdown_wikilinks
intrude import markdown_inline_parsing
intrude import markdown_block_parsing
redef class MdParser
# Enable wikilinks mode
var wikilinks_mode = false is writable
redef var inline_parser is lazy do
var parser = super
parser.wikilinks_mode = wikilinks_mode
return parser
end
end
redef class MdInlineParser
# Enable wikilinks mode
private var wikilinks_mode = false
redef fun parse_wikilink do
if not wikilinks_mode then return false
# do we have two opening bracket?
var last_bracket = self.last_bracket
if last_bracket == null then return false
var first_bracket = last_bracket.prev
if first_bracket == null then return false
# was the first bracket an image?
if first_bracket.is_image then return false
# do we have two closing brackets?
if index >= input.length or input.chars[index] != ']' then return false
advance 1 # skip last bracket
var start_index = first_bracket.index + 2
var end_index = index - 2
# create wikilink node
var content = input.substring(start_index, end_index - start_index)
var parts = content.split("|")
var title = if parts.length > 1 then parts.first.trim else null
var link = parts.last.trim
var wikilink = new MdWikilink(
new MdLocation(
first_bracket.node.location.line_start,
first_bracket.node.location.column_start - 1,
line,
column - 1),
link, title)
var node = last_bracket.node.next
var in_link = false
while node != null do
var next = node.next
if not in_link then
if node isa MdText and node.literal.has("|") then
var buf = new Buffer
for c in node.literal.chars do
if c == '|' then
in_link = true
break
end
buf.add c
end
node.literal = buf.write_to_string.r_trim
end
wikilink.append_child(node)
else
node.unlink
end
node = next
end
append_node(wikilink)
# Process delimiters such as emphasis inside a link/image
process_delimiters(last_bracket.prev_delimiter)
merge_child_text_nodes(wikilink)
# remove brackets
first_bracket.node.unlink
last_bracket.node.unlink
return true
end
end
# A Wikilink node
class MdWikilink
super MdNode
# Wikilink link
var link: String is writable
# Wikilink title
var title: nullable String = null is optional, writable
end
lib/markdown2/markdown_wikilinks.nit:15,1--119,3