X-Git-Url: http://nitlanguage.org diff --git a/contrib/nitiwiki/src/wiki_links.nit b/contrib/nitiwiki/src/wiki_links.nit index bbbfea0..b542ff2 100644 --- a/contrib/nitiwiki/src/wiki_links.nit +++ b/contrib/nitiwiki/src/wiki_links.nit @@ -16,7 +16,7 @@ module wiki_links import wiki_base -intrude import markdown +import markdown::wikilinks redef class Nitiwiki # Looks up a WikiEntry by its `name`. @@ -29,7 +29,7 @@ redef class Nitiwiki # # Returns `null` if no article can be found. fun lookup_entry_by_name(context: WikiEntry, name: String): nullable WikiEntry do - var section = context.parent + var section: nullable WikiEntry = context.parent or else context var res = section.lookup_entry_by_name(name) if res != null then return res while section != null do @@ -50,7 +50,7 @@ redef class Nitiwiki # # Returns `null` if no article can be found. fun lookup_entry_by_title(context: WikiEntry, title: String): nullable WikiEntry do - var section = context.parent + var section: nullable WikiEntry = context.parent or else context var res = section.lookup_entry_by_title(title) if res != null then return res while section != null do @@ -70,7 +70,7 @@ redef class Nitiwiki # # Returns `null` if no article can be found. fun lookup_entry_by_path(context: WikiEntry, path: String): nullable WikiEntry do - var entry = context.parent + var entry: nullable WikiEntry = context.parent or else context var parts = path.split_with("/") if path.has_prefix("/") then entry = root_section @@ -189,16 +189,6 @@ class NitiwikiMdProcessor emitter = new MarkdownEmitter(self) emitter.decorator = new NitiwikiDecorator(wiki, context) end - - redef fun token_at(text, pos) do - var token = super - if not token isa TokenLink then return token - if pos + 1 < text.length then - var c = text[pos + 1] - if c == '[' then return new TokenWikiLink(pos, c) - end - return token - end end private class NitiwikiDecorator @@ -210,7 +200,7 @@ private class NitiwikiDecorator # Article used to contextualize links. var context: WikiArticle - fun add_wikilink(v: MarkdownEmitter, link: Text, name, comment: nullable Text) do + redef fun add_wikilink(v, link, name, comment) do var wiki = v.processor.as(NitiwikiMdProcessor).wiki var target: nullable WikiEntry = null var anchor: nullable String = null @@ -250,46 +240,3 @@ private class NitiwikiDecorator v.add "" end end - -# A NitiWiki link token. -# -# Something of the form `[[foo]]`. -# -# Allowed formats: -# -# * `[[Wikilink]]` -# * `[[Wikilink/Bar]]` -# * `[[Wikilink#foo]]` -# * `[[Wikilink/Bar#foo]]` -# * `[[title|Wikilink]]` -# * `[[title|Wikilink/Bar]]` -# * `[[title|Wikilink/Bar#foo]]` -class TokenWikiLink - super TokenLink - - redef fun emit_hyper(v) do - v.decorator.as(NitiwikiDecorator).add_wikilink(v, link.as(not null), name, comment) - end - - redef fun check_link(v, out, start, token) do - var md = v.current_text - 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 - pos += 1 - return pos - end -end