Merge: markdown: merge MDProcessor and MDEmitter
[nit.git] / contrib / nitiwiki / src / wiki_links.nit
index c1785b2..7d81633 100644 (file)
@@ -31,7 +31,7 @@ redef class Nitiwiki
        # 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
@@ -52,7 +52,7 @@ redef class Nitiwiki
        # 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
@@ -168,7 +168,7 @@ redef class WikiEntry
                var blocks = sidebar.blocks
                for i in [0..blocks.length[ do
                        blocks[i] = md_proc.process(blocks[i].to_s).write_to_string
-                       md_proc.emitter.decorator.headlines.clear
+                       md_proc.decorator.headlines.clear
                end
        end
 end
@@ -200,6 +200,7 @@ 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
@@ -211,7 +212,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.decorator.headlines)
        end
 end
 
@@ -242,8 +243,7 @@ class NitiwikiMdProcessor
        var context: WikiEntry
 
        init do
-               emitter = new MarkdownEmitter(self)
-               emitter.decorator = new NitiwikiDecorator(wiki, context)
+               decorator = new NitiwikiDecorator(wiki, context)
        end
 end
 
@@ -258,7 +258,7 @@ class NitiwikiDecorator
        var context: WikiEntry
 
        redef fun add_wikilink(v, token) do
-               var wiki = v.processor.as(NitiwikiMdProcessor).wiki
+               var wiki = v.as(NitiwikiMdProcessor).wiki
                var target: nullable WikiEntry = null
                var anchor: nullable String = null
                var link = token.link