X-Git-Url: http://nitlanguage.org diff --git a/contrib/nitiwiki/src/wiki_links.nit b/contrib/nitiwiki/src/wiki_links.nit index 2e9cf59..efb9f78 100644 --- a/contrib/nitiwiki/src/wiki_links.nit +++ b/contrib/nitiwiki/src/wiki_links.nit @@ -54,9 +54,9 @@ redef class Nitiwiki var res = section.lookup_entry_by_title(title) if res != null then return res while section != null do - if section.title == title then return section + if section.title.to_lower == title.to_lower then return section for child in section.children.values do - if child.title == title then return child + if child.title.to_lower == title.to_lower then return child end section = section.parent end @@ -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: nullable WikiEntry = context.parent or else context + var entry = context.parent or else context var parts = path.split_with("/") if path.has_prefix("/") then entry = root_section @@ -80,6 +80,7 @@ redef class Nitiwiki while not parts.is_empty do var name = parts.shift if name.is_empty then continue + if entry.name == name then continue if not entry.children.has_key(name) then return null entry = entry.children[name] end @@ -89,8 +90,17 @@ end redef class WikiEntry - # Url to `self` once generated. - fun url: String do return wiki.config.root_url.join_path(breadcrumbs.join("/")) + # Relative path to `self` from the target root_url + fun href: String do return breadcrumbs.join("/") + + # A relative `href` to `self` from the page `context`. + # + # Should be used to navigate between documents. + fun href_from(context: WikiEntry): String + do + var res = context.href.dirname.relpath(href) + return res + end redef fun render do super @@ -111,7 +121,7 @@ redef class WikiEntry # Search in `self` then `self.children` if an entry has the title `title`. fun lookup_entry_by_title(title: String): nullable WikiEntry do for child in children.values do - if child.title == title then return child + if child.title.to_lower == title.to_lower then return child end for child in children.values do var res = child.lookup_entry_by_title(title) @@ -158,11 +168,11 @@ redef class WikiArticle # Checks if `self.name == "index"`. fun is_index: Bool do return name == "index" - redef fun url do + redef fun href do if parent == null then - return wiki.config.root_url.join_path("{name}.html") + return "{name}.html" else - return parent.url.join_path("{name}.html") + return parent.href.join_path("{name}.html") end end @@ -183,7 +193,7 @@ class WikiSectionIndex redef fun title do return section.title - redef fun url do return section.url + redef fun href do return section.href end # A MarkdownProcessor able to parse wiki links. @@ -204,7 +214,8 @@ class NitiwikiMdProcessor end end -private class NitiwikiDecorator +# The decorator associated to `MarkdownProcessor`. +class NitiwikiDecorator super HTMLDecorator # Wiki used to resolve links. @@ -213,36 +224,41 @@ private class NitiwikiDecorator # Article used to contextualize links. var context: WikiEntry - redef fun add_wikilink(v, link, name, comment) do + redef fun add_wikilink(v, token) do var wiki = v.processor.as(NitiwikiMdProcessor).wiki var target: nullable WikiEntry = null var anchor: nullable String = null - if link.has("#") then - var parts = link.split_with("#") - link = parts.first - anchor = parts.subarray(1, parts.length - 1).join("#") - end - if link.has("/") then - target = wiki.lookup_entry_by_path(context, link.to_s) - else - target = wiki.lookup_entry_by_name(context, link.to_s) - if target == null then - target = wiki.lookup_entry_by_title(context, link.to_s) - end - end + var link = token.link + if link == null then return + var name = token.name v.add "