X-Git-Url: http://nitlanguage.org diff --git a/contrib/nitiwiki/src/wiki_html.nit b/contrib/nitiwiki/src/wiki_html.nit index 7f213b7..46518aa 100644 --- a/contrib/nitiwiki/src/wiki_html.nit +++ b/contrib/nitiwiki/src/wiki_html.nit @@ -15,12 +15,14 @@ # HTML wiki rendering module wiki_html -import wiki_base +import wiki_links +import markdown::decorators redef class Nitiwiki # Render HTML output looking for changes in the markdown sources. - fun render do + redef fun render do + super if not root_section.is_dirty and not force_render then return var out_dir = expand_path(config.root_dir, config.out_dir) out_dir.mkdir @@ -44,15 +46,23 @@ redef class Nitiwiki sitemap.is_dirty = true return sitemap end -end -redef class WikiEntry + # Markdown processor used for inline element such as titles in TOC. + private var inline_processor: MarkdownProcessor is lazy do + var proc = new MarkdownProcessor + proc.emitter.decorator = new InlineDecorator + return proc + end - # Url to `self` once generated. - fun url: String do return wiki.config.root_url.join_path(breadcrumbs.join("/")) + # Inline markdown (remove h1, p, ... elements). + private fun inline_md(md: Writable): Writable do + return inline_processor.process(md.write_to_string) + end +end +redef class WikiEntry # Get a `` template link to `self` - fun tpl_link: Streamable do + fun tpl_link: Writable do return "{title}" end end @@ -81,6 +91,7 @@ redef class WikiSection end var index = self.index if index isa WikiSectionIndex then + wiki.message("Render auto-index for section {out_path}", 1) index.is_dirty = true add_child index end @@ -102,17 +113,6 @@ redef class WikiSection end end - # The index page for this section. - # - # If no file `index.md` exists for this section, - # a summary is generated using contained articles. - fun index: WikiArticle is cached do - for child in children.values do - if child isa WikiArticle and child.is_index then return child - end - return new WikiSectionIndex(wiki, "index", self) - end - redef fun tpl_link do return index.tpl_link # Render the section hierarchy as a html tree. @@ -172,26 +172,13 @@ redef class WikiArticle end end - redef fun url do - if parent == null then - return wiki.config.root_url.join_path("{name}.html") - else - return parent.url.join_path("{name}.html") - end - end - - # Is `self` an index page? - # - # Checks if `self.name == "index"`. - fun is_index: Bool do return name == "index" - redef fun render do + super if not is_dirty and not wiki.force_render then return wiki.message("Render article {name}", 2) var file = out_full_path file.dirname.mkdir tpl_page.write_to_file file - super end @@ -214,7 +201,7 @@ redef class WikiArticle end # Generate the HTML header for this article. - fun tpl_header: Streamable do + fun tpl_header: Writable do var file = header_file if not wiki.has_template(file) then return "" return wiki.load_template(file) @@ -236,7 +223,7 @@ redef class WikiArticle # Generate the HTML summary for this article. # # Based on `headlines` - fun tpl_summary: Streamable do + fun tpl_summary: Writable do var headlines = self.headlines var tpl = new Template tpl.add "