nitiwiki: change some visibility to allow extensions
[nit.git] / contrib / nitiwiki / src / wiki_links.nit
index 6dfee80..efb9f78 100644 (file)
@@ -90,10 +90,6 @@ end
 
 redef class WikiEntry
 
-       # Absolute url to `self` once generated.
-       # If you use this, the generated files will hard-code `root_url`
-       fun url: String do return wiki.config.root_url / href
-
        # Relative path to `self` from the target root_url
        fun href: String do return breadcrumbs.join("/")
 
@@ -218,7 +214,8 @@ class NitiwikiMdProcessor
        end
 end
 
-private class NitiwikiDecorator
+# The decorator associated to `MarkdownProcessor`.
+class NitiwikiDecorator
        super HTMLDecorator
 
        # Wiki used to resolve links.
@@ -227,12 +224,15 @@ 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
+               var link = token.link
+               if link == null then return
+               var name = token.name
                v.add "<a "
                if not link.has_prefix("http://") and not link.has_prefix("https://") then
-                       var wiki = v.processor.as(NitiwikiMdProcessor).wiki
-                       var target: nullable WikiEntry = null
                        if link.has("#") then
                                var parts = link.split_with("#")
                                link = parts.first
@@ -248,10 +248,9 @@ private class NitiwikiDecorator
                        end
                        if target != null then
                                if name == null then name = target.title
-                               link = target.url
+                               link = target.href_from(context)
                        else
-                               var loc = context.src_path or else context.name
-                               wiki.message("Warning: unknown wikilink `{link}` (in {loc})", 0)
+                               wiki.message("Warning: unknown wikilink `{link}` (in {context.src_path.as(not null)})", 0)
                                v.add "class=\"broken\" "
                        end
                end
@@ -259,6 +258,7 @@ private class NitiwikiDecorator
                append_value(v, link)
                if anchor != null then append_value(v, "#{anchor}")
                v.add "\""
+               var comment = token.comment
                if comment != null and not comment.is_empty then
                        v.add " title=\""
                        append_value(v, comment)