X-Git-Url: http://nitlanguage.org
diff --git a/contrib/nitiwiki/src/wiki_links.nit b/contrib/nitiwiki/src/wiki_links.nit
index 6dfee80..ac3e171 100644
--- a/contrib/nitiwiki/src/wiki_links.nit
+++ b/contrib/nitiwiki/src/wiki_links.nit
@@ -17,6 +17,7 @@ module wiki_links
import wiki_base
import markdown::wikilinks
+import ordered_tree
redef class Nitiwiki
# Looks up a WikiEntry by its `name`.
@@ -86,26 +87,50 @@ redef class Nitiwiki
end
return entry
end
+
+ # Trails between pages
+ #
+ # Trails are represented as a forest of entries.
+ # This way it is possible to represent a flat-trail as a visit of a tree.
+ var trails = new OrderedTree[WikiEntry]
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("/")
+ # Relative path to the directory `self` from the target root_url
+ fun dir_href: String do return href.dirname
+
+ # Relative path to the root url from `self`
+ fun root_href: String do
+ var root_dir = dir_href.relpath("")
+ # Avoid issues if used as a macro just followed by a `/` (as with url prefix)
+ if root_dir == "" then root_dir = "."
+ return root_dir
+ end
+
# 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)
+ var res = context.dir_href.relpath(href)
return res
end
+ # A relative hyperlink to `self` from the page `context`.
+ #
+ # If `text` is not given, `title` will be used instead.
+ fun a_from(context: WikiEntry, text: nullable Text): Writable
+ do
+ var title = title.html_escape
+ if text == null then text = title else text = text.html_escape
+ var href = href_from(context)
+ return """{{{text}}}"""
+ end
+
redef fun render do
super
if not is_dirty and not wiki.force_render then return
@@ -160,6 +185,8 @@ redef class WikiSection
end
return new WikiSectionIndex(wiki, "index", self)
end
+
+ redef fun dir_href do return href
end
redef class WikiArticle
@@ -184,7 +211,7 @@ redef class WikiArticle
super
if not is_dirty and not wiki.force_render or not has_source then return
content = md_proc.process(md.as(not null))
- headlines.recover_with(md_proc.emitter.decorator.headlines)
+ headlines.add_all(md_proc.emitter.decorator.headlines)
end
end
@@ -198,6 +225,8 @@ class WikiSectionIndex
redef fun title do return section.title
redef fun href do return section.href
+
+ redef fun dir_href do return section.dir_href
end
# A MarkdownProcessor able to parse wiki links.
@@ -218,7 +247,8 @@ class NitiwikiMdProcessor
end
end
-private class NitiwikiDecorator
+# The decorator associated to `MarkdownProcessor`.
+class NitiwikiDecorator
super HTMLDecorator
# Wiki used to resolve links.
@@ -227,12 +257,23 @@ 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 " 1 then
+ command = command_split[0].trim
+ link = command_split[1].trim
+ end
+
if link.has("#") then
var parts = link.split_with("#")
link = parts.first
@@ -248,10 +289,14 @@ private class NitiwikiDecorator
end
if target != null then
if name == null then name = target.title
- link = target.url
+ link = target.href_from(context)
+
+ if command == "trail" then
+ if target isa WikiSection then target = target.index
+ wiki.trails.add(context, target)
+ end
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 +304,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)