import wiki_base
import markdown::wikilinks
+import ordered_tree
redef class Nitiwiki
# Looks up a WikiEntry by its `name`.
# Returns `null` if no article can be found.
fun lookup_entry_by_name(context: WikiEntry, name: String): nullable WikiEntry do
var section: nullable WikiEntry = context.parent or else context
- var res = section.lookup_entry_by_name(name)
+ var res = section.as(not null).lookup_entry_by_name(name)
if res != null then return res
while section != null do
if section.name == name then return section
# Returns `null` if no article can be found.
fun lookup_entry_by_title(context: WikiEntry, title: String): nullable WikiEntry do
var section: nullable WikiEntry = context.parent or else context
- var res = section.lookup_entry_by_title(title)
+ var res = section.as(not null).lookup_entry_by_title(title)
if res != null then return res
while section != null do
if section.title.to_lower == title.to_lower then return section
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
# 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
end
return new WikiSectionIndex(wiki, "index", self)
end
+
+ redef fun dir_href do return href
end
redef class WikiArticle
fun is_index: Bool do return name == "index"
redef fun href do
+ var parent = self.parent
if parent == null then
return "{name}.html"
else
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
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.
if target != null then
if name == null then name = target.title
link = target.href_from(context)
+
+ if command == "trail" then
+ if target isa WikiSection then target = target.index
+ wiki.trails.add(context, target)
+ end
else
wiki.message("Warning: unknown wikilink `{link}` (in {context.src_path.as(not null)})", 0)
v.add "class=\"broken\" "