nitiwiki: use `InlineDecorator` for markdown titles in TOC
authorAlexandre Terrasa <alexandre@moz-code.org>
Thu, 21 May 2015 18:12:24 +0000 (14:12 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Mon, 25 May 2015 15:17:05 +0000 (11:17 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

contrib/nitiwiki/src/wiki_html.nit

index 461e9e5..46518aa 100644 (file)
@@ -16,6 +16,7 @@
 module wiki_html
 
 import wiki_links
+import markdown::decorators
 
 redef class Nitiwiki
 
@@ -45,6 +46,18 @@ redef class Nitiwiki
                sitemap.is_dirty = true
                return sitemap
        end
+
+       # 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
+
+       # 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
@@ -218,8 +231,7 @@ redef class WikiArticle
                while iter.is_ok do
                        var hl = iter.item
                        # parse title as markdown
-                       var title = hl.title.md_to_html.to_s
-                       title = title.substring(3, title.length - 8)
+                       var title = wiki.inline_md(hl.title)
                        tpl.add "<li><a href=\"#{hl.id}\">{title}</a>"
                        iter.next
                        if iter.is_ok then