ni_nitdoc: moved QuickSearch js to it's own file
[nit.git] / src / ni_nitdoc.nit
index afd7b88..61f9f7a 100644 (file)
@@ -1,7 +1,5 @@
 # This file is part of NIT ( http://www.nitlanguage.org ).
 #
-# Copyright 2008 Jean Privat <jean@pryen.org>
-#
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # You may obtain a copy of the License at
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+# Documentation generator for the nit language.
+# Generate API documentation in HTML format from nit source code.
 module ni_nitdoc
 
 import model_utils
-import abstract_compiler
+import modelize_property
+import markdown
 
 # The NitdocContext contains all the knowledge used for doc generation
 class NitdocContext
-       super ToolContext
 
+       private var toolcontext = new ToolContext
        private var model: Model
-       private var modelbuilder: ModelBuilder
+       private var mbuilder: ModelBuilder
        private var mainmodule: MModule
        private var class_hierarchy: POSet[MClass]
        private var arguments: Array[String]
@@ -45,32 +46,36 @@ class NitdocContext
        private var opt_custom_overview_text: OptionString = new OptionString("Text displayed as introduction of Overview page before the modules list", "--custom-overview-text")
        private var opt_custom_footer_text: OptionString = new OptionString("Text displayed as footer of all pages", "--custom-footer-text")
 
+       private var opt_github_base: OptionString = new OptionString("The branch (or git ref) edited commits will be pulled into (ex: octocat:master)", "--github-base")
+       private var opt_github_head: OptionString = new OptionString("The reference branch name used to create pull requests (ex: master)", "--github-head")
+
        init do
-               super
-               self.arguments = option_context.rest
-               option_context.options.clear
-               option_context.add_option(opt_dir)
-               option_context.add_option(opt_source)
-               option_context.add_option(opt_sharedir)
-               option_context.add_option(opt_nodot)
-               option_context.add_option(opt_private)
-               option_context.add_option(opt_custom_title)
-               option_context.add_option(opt_custom_footer_text)
-               option_context.add_option(opt_custom_overview_text)
-               option_context.add_option(opt_custom_menu_items)
-               process_options
+               toolcontext.option_context.add_option(opt_dir)
+               toolcontext.option_context.add_option(opt_source)
+               toolcontext.option_context.add_option(opt_sharedir)
+               toolcontext.option_context.add_option(opt_nodot)
+               toolcontext.option_context.add_option(opt_private)
+               toolcontext.option_context.add_option(opt_custom_title)
+               toolcontext.option_context.add_option(opt_custom_footer_text)
+               toolcontext.option_context.add_option(opt_custom_overview_text)
+               toolcontext.option_context.add_option(opt_custom_menu_items)
+               toolcontext.option_context.add_option(opt_github_base)
+               toolcontext.option_context.add_option(opt_github_head)
+               toolcontext.process_options
+               self.arguments = toolcontext.option_context.rest
 
                if arguments.length < 1 then
-                       option_context.usage
+                       print "usage: nitdoc [options] file..."
+                       toolcontext.option_context.usage
                        exit(1)
                end
 
                model = new Model
-               modelbuilder = new ModelBuilder(model, self)
+               mbuilder = new ModelBuilder(model, toolcontext)
                # Here we load an process all modules passed on the command line
-               var mmodules = modelbuilder.parse_and_build(arguments)
-               modelbuilder.full_propdef_semantic_analysis
+               var mmodules = mbuilder.parse(arguments)
                if mmodules.is_empty then return
+               mbuilder.run_phases
 
                if mmodules.length == 1 then
                        mainmodule = mmodules.first
@@ -80,10 +85,10 @@ class NitdocContext
                        mainmodule.set_imported_mmodules(mmodules)
                end
                self.class_hierarchy = mainmodule.flatten_mclass_hierarchy
+               self.process_options
        end
 
-       redef fun process_options do
-               super
+       private fun process_options do
                if not opt_dir.value is null then
                        output_dir = opt_dir.value
                else
@@ -94,9 +99,9 @@ class NitdocContext
                else
                        var dir = "NIT_DIR".environ
                        if dir.is_empty then
-                               dir = "{sys.program_name.dirname}/../share/nitdoc"
+                               dir = "{sys.program_name.dirname}/../share/ni_nitdoc"
                        else
-                               dir = "{dir}/share/nitdoc"
+                               dir = "{dir}/share/ni_nitdoc"
                        end
                        share_dir = dir
                        if share_dir is null then
@@ -125,7 +130,7 @@ class NitdocContext
                self.dot_dir = null
                if not opt_nodot.value then self.dot_dir = output_dir.to_s
                overview
-               fullindex
+               search
                modules
                classes
                quicksearch_list
@@ -136,9 +141,9 @@ class NitdocContext
                overviewpage.save("{output_dir.to_s}/index.html")
        end
 
-       private fun fullindex do
-               var fullindex = new NitdocFullindex(self)
-               fullindex.save("{output_dir.to_s}/full-index.html")
+       private fun search do
+               var searchpage = new NitdocSearch(self)
+               searchpage.save("{output_dir.to_s}/search.html")
        end
 
        private fun modules do
@@ -150,7 +155,7 @@ class NitdocContext
        end
 
        private fun classes do
-               for mclass in modelbuilder.model.mclasses do
+               for mclass in mbuilder.model.mclasses do
                        var classpage = new NitdocClass(mclass, self, dot_dir, source)
                        classpage.save("{output_dir.to_s}/{mclass.url}")
                end
@@ -158,19 +163,17 @@ class NitdocContext
 
        private fun quicksearch_list do
                var file = new OFStream.open("{output_dir.to_s}/quicksearch-list.js")
-               var content = new Buffer
-               content.append("var entries = \{ ")
-
+               file.write("var entries = \{ ")
                for mmodule in model.mmodules do
-                       content.append("\"{mmodule.name}\": [")
-                       content.append("\{txt: \"{mmodule.name}\", url:\"{mmodule.url}\" \},")
-                       content.append("],")
+                       file.write("\"{mmodule.name}\": [")
+                       file.write("\{txt: \"{mmodule.full_name}\", url:\"{mmodule.url}\" \},")
+                       file.write("],")
                end
                for mclass in model.mclasses do
                        if mclass.visibility < min_visibility then continue
-                       content.append("\"{mclass.name}\": [")
-                       content.append("\{txt: \"{mclass.name}\", url:\"{mclass.url}\" \},")
-                       content.append("],")
+                       file.write("\"{mclass.name}\": [")
+                       file.write("\{txt: \"{mclass.full_name}\", url:\"{mclass.url}\" \},")
+                       file.write("],")
                end
                var name2mprops = new HashMap[String, Set[MPropDef]]
                for mproperty in model.mproperties do
@@ -180,15 +183,13 @@ class NitdocContext
                        name2mprops[mproperty.name].add_all(mproperty.mpropdefs)
                end
                for mproperty, mpropdefs in name2mprops do
-                       content.append("\"{mproperty}\": [")
+                       file.write("\"{mproperty}\": [")
                        for mpropdef in mpropdefs do
-                               content.append("\{txt: \"{mpropdef.full_name}\", url:\"{mpropdef.url}\" \},")
+                               file.write("\{txt: \"{mpropdef.full_name}\", url:\"{mpropdef.url}\" \},")
                        end
-                       content.append("],")
+                       file.write("],")
                end
-
-               content.append(" \};")
-               file.write(content.to_s)
+               file.write(" \};")
                file.close
        end
 
@@ -205,15 +206,18 @@ abstract class NitdocPage
                self.ctx = ctx
        end
 
-       fun append(str: String) do html.append(str)
-       private var html = new Buffer
-
        protected fun head do
                append("<meta charset='utf-8'/>")
                append("<script type='text/javascript' src='scripts/jquery-1.7.1.min.js'></script>")
+               append("<script type='text/javascript' src='scripts/ZeroClipboard.min.js'></script>")
+               append("<script type='text/javascript' src='scripts/Markdown.Converter.js'></script>")
                append("<script type='text/javascript' src='quicksearch-list.js'></script>")
+               append("<script type='text/javascript' src='scripts/base64.js'></script>")
+               append("<script type='text/javascript' src='scripts/github.js'></script>")
                append("<script type='text/javascript' src='scripts/js-facilities.js'></script>")
+               append("<script type='text/javascript' src='scripts/Nitdoc.QuickSearch.js'></script>")
                append("<link rel='stylesheet' href='styles/main.css' type='text/css' media='screen'/>")
+               append("<link rel='stylesheet' href='styles/github.css' type='text/css' media='screen'/>")
                var title = ""
                if ctx.opt_custom_title.value != null then
                        title = " | {ctx.opt_custom_title.value.to_s}"
@@ -234,43 +238,6 @@ abstract class NitdocPage
                append("<nav class='main'>")
                append("<ul>")
                menu
-               append("<li id='liGitHub'>")
-               append("<a class='btn' id='logGitHub'>")
-               append("<img id='imgGitHub' src='resources/icons/github-icon.png' alt='GitHub'/>")
-               append("</a>")
-               append("<div class='popover bottom'>")
-               append("<div class='arrow'>&nbsp;</div>")
-               append("<div class='githubTitle'>")
-               append("<h3>Github Sign In</h3>")
-               append("</div>")
-               append("<div>")
-               append("<label id='lbloginGit'>Username</label>")
-               append("<input id='loginGit' name='login' type='text'/>")
-               append("<label id='logginMessage'>Hello ")
-               append("<a id='githubAccount'><strong id='nickName'></strong></a>")
-               append("</label>")
-               append("</div>")
-               append("<div>")
-               append("<label id='lbpasswordGit'>Password</label>")
-               append("<input id='passwordGit' name='password' type='password'/>")
-               append("<div id='listBranches'>")
-               append("<label id='lbBranches'>Branch</label>")
-               append("<select class='dropdown' id='dropBranches' name='dropBranches' tabindex='1'></select>")
-               append("</div>")
-               append("</div>")
-               append("<div>")
-               append("<label id='lbrepositoryGit'>Repository</label>")
-               append("<input id='repositoryGit' name='repository' type='text'/>")
-               append("</div>")
-               append("<div>")
-               append("<label id='lbbranchGit'>Branch</label>")
-               append("<input id='branchGit' name='branch' type='text'/>")
-               append("</div>")
-               append("<div>")
-               append("<a id='signIn'>Sign In</a>")
-               append("</div>")
-               append("</div>")
-               append("</li>")
                append("</ul>")
                append("</nav>")
                append("</header>")
@@ -313,32 +280,42 @@ abstract class NitdocPage
                        source = x.join(l.line_start.to_s)
                        x = source.split_with("%L")
                        source = x.join(l.line_end.to_s)
-                       return " (<a href=\"{source.to_s}\">source</a>)"
+                       return " (<a target='_blank' title='Show source' href=\"{source.to_s}\">source</a>)"
                end
        end
 
        # Render the page as a html string
-       fun render: String do
+       protected fun render do
                append("<!DOCTYPE html>")
                append("<head>")
                head
                append("</head>")
-               append("<body>")
+               append("<body")
+               if not ctx.opt_github_base.value == null and not ctx.opt_github_head.value == null then
+                       append(" data-github-base='{ctx.opt_github_base.value.as(not null)}'")
+                       append(" data-github-head='{ctx.opt_github_head.value.as(not null)}'")
+               end
+               append(">")
                header
-               append("<div class='page'>")
+               var footed = ""
+               if ctx.opt_custom_footer_text.value != null then footed = "footed"
+               append("<div class='page {footed}'>")
                content
                append("</div>")
                footer
                append("</body>")
-               return html.to_s
        end
 
+       # Append a string to the page
+       fun append(s: String) do out.write(s)
+
        # Save html page in the specified file
        fun save(file: String) do
-               var out = new OFStream.open(file)
-               out.write(render)
-               out.close
+               self.out = new OFStream.open(file)
+               render
+               self.out.close
        end
+       private var out: nullable OFStream
 end
 
 # The overview page
@@ -349,7 +326,7 @@ class NitdocOverview
 
        init(ctx: NitdocContext, dot_dir: nullable String) do
                super(ctx)
-               self.mbuilder = ctx.modelbuilder
+               self.mbuilder = ctx.mbuilder
                self.dot_dir = dot_dir
                # get modules
                var mmodules = new HashSet[MModule]
@@ -363,7 +340,7 @@ class NitdocOverview
                        end
                end
                # sort modules
-               var sorter = new ComparableSorter[MModule]
+               var sorter = new MModuleNameSorter
                self.mmodules.add_all(mmodules)
                sorter.sort(self.mmodules)
        end
@@ -373,7 +350,7 @@ class NitdocOverview
        redef fun menu do
                super
                append("<li class='current'>Overview</li>")
-               append("<li><a href='full-index.html'>Full Index</a></li>")
+               append("<li><a href='search.html'>Search</a></li>")
        end
 
        redef fun content do
@@ -395,7 +372,9 @@ class NitdocOverview
                for mmodule in mmodules do
                        if mbuilder.mmodule2nmodule.has_key(mmodule) then
                                var amodule = mbuilder.mmodule2nmodule[mmodule]
-                               append("<li>{mmodule.link(mbuilder)}&nbsp;{amodule.short_comment}</li>")
+                               append("<li>")
+                               mmodule.html_link(self)
+                               append("&nbsp;{amodule.short_comment}</li>")
                        end
                end
                append("</ul>")
@@ -406,14 +385,25 @@ class NitdocOverview
        end
 
        private fun process_generate_dot do
+               # build poset with public owners
+               var poset = new POSet[MModule]
+               for mmodule in mmodules do
+                       poset.add_node(mmodule)
+                       for omodule in mmodules do
+                               if mmodule == omodule then continue
+                               if mmodule.in_importation < omodule then
+                                       poset.add_node(omodule)
+                                       poset.add_edge(mmodule, omodule)
+                               end
+                       end
+               end
+               # build graph
                var op = new Buffer
                op.append("digraph dep \{ rankdir=BT; node[shape=none,margin=0,width=0,height=0,fontsize=10]; edge[dir=none,color=gray]; ranksep=0.2; nodesep=0.1;\n")
-               for mmodule in mmodules do
+               for mmodule in poset do
                        op.append("\"{mmodule.name}\"[URL=\"{mmodule.url}\"];\n")
-                       for imported in mmodule.in_importation.direct_greaters do
-                               if imported.direct_owner == null then
-                                       op.append("\"{mmodule.name}\"->\"{imported.name}\";\n")
-                               end
+                       for omodule in poset[mmodule].direct_greaters do
+                               op.append("\"{mmodule.name}\"->\"{omodule.name}\";\n")
                        end
                end
                op.append("\}\n")
@@ -421,8 +411,8 @@ class NitdocOverview
        end
 end
 
-# The full index page
-class NitdocFullindex
+# The search page
+class NitdocSearch
        super NitdocPage
 
        init(ctx: NitdocContext) do
@@ -430,17 +420,17 @@ class NitdocFullindex
                self.dot_dir = null
        end
 
-       redef fun title do return "Full Index"
+       redef fun title do return "Search"
 
        redef fun menu do
                super
                append("<li><a href='index.html'>Overview</a></li>")
-               append("<li class='current'>Full Index</li>")
+               append("<li class='current'>Search</li>")
        end
 
        redef fun content do
                append("<div class='content fullpage'>")
-               append("<h1>Full Index</h1>")
+               append("<h1>{title}</h1>")
                module_column
                classes_column
                properties_column
@@ -449,17 +439,16 @@ class NitdocFullindex
 
        # Add to content modules column
        private fun module_column do
-               var sorter = new ComparableSorter[MModule]
-               var sorted = new Array[MModule]
-               for mmodule in ctx.modelbuilder.model.mmodule_importation_hierarchy do
-                       sorted.add(mmodule)
-               end
+               var sorted = ctx.mbuilder.model.mmodule_importation_hierarchy.to_a
+               var sorter = new MModuleNameSorter
                sorter.sort(sorted)
                append("<article class='modules filterable'>")
                append("<h2>Modules</h2>")
                append("<ul>")
                for mmodule in sorted do
-                       append("<li>{mmodule.link(ctx.modelbuilder)}</li>")
+                       append("<li>")
+                       mmodule.html_link(self)
+                       append("</li>")
                end
                append("</ul>")
                append("</article>")
@@ -467,15 +456,17 @@ class NitdocFullindex
 
        # Add to content classes modules
        private fun classes_column do
-               var sorted = ctx.modelbuilder.model.mclasses
-               var sorter = new ComparableSorter[MClass]
+               var sorted = ctx.mbuilder.model.mclasses
+               var sorter = new MClassNameSorter
                sorter.sort(sorted)
                append("<article class='modules filterable'>")
                append("<h2>Classes</h2>")
                append("<ul>")
                for mclass in sorted do
                        if mclass.visibility < ctx.min_visibility then continue
-                       append("<li>{mclass.link(ctx.modelbuilder)}</li>")
+                       append("<li>")
+                       mclass.html_link(self)
+                       append("</li>")
                end
                append("</ul>")
                append("</article>")
@@ -483,8 +474,8 @@ class NitdocFullindex
 
        # Insert the properties column of fullindex page
        private fun properties_column do
-               var sorted = ctx.modelbuilder.model.mproperties
-               var sorter = new ComparableSorter[MProperty]
+               var sorted = ctx.mbuilder.model.mproperties
+               var sorter = new MPropertyNameSorter
                sorter.sort(sorted)
                append("<article class='modules filterable'>")
                append("<h2>Properties</h2>")
@@ -492,7 +483,11 @@ class NitdocFullindex
                for mproperty in sorted do
                        if mproperty.visibility < ctx.min_visibility then continue
                        if mproperty isa MAttribute then continue
-                       append("<li>{mproperty.intro.link(ctx.modelbuilder)} ({mproperty.intro.mclassdef.mclass.link(ctx.modelbuilder)})</li>")
+                       append("<li>")
+                       mproperty.intro.html_link(self)
+                       append(" (")
+                       mproperty.intro.mclassdef.mclass.html_link(self)
+                       append(")</li>")
                end
                append("</ul>")
                append("</article>")
@@ -506,84 +501,93 @@ class NitdocModule
 
        private var mmodule: MModule
        private var mbuilder: ModelBuilder
+       private var local_mclasses = new HashSet[MClass]
+       private var intro_mclasses = new HashSet[MClass]
+       private var redef_mclasses = new HashSet[MClass]
 
        init(mmodule: MModule, ctx: NitdocContext, dot_dir: nullable String) do
                super(ctx)
                self.mmodule = mmodule
-               self.mbuilder = ctx.modelbuilder
+               self.mbuilder = ctx.mbuilder
                self.dot_dir = dot_dir
+               # get local mclasses
+               for m in mmodule.in_nesting.greaters do
+                       for mclassdef in m.mclassdefs do
+                               if mclassdef.mclass.visibility < ctx.min_visibility then continue
+                               if mclassdef.is_intro then
+                                       intro_mclasses.add(mclassdef.mclass)
+                               else
+                                       if mclassdef.mclass.mpropdefs_in_module(self).is_empty then continue
+                                       redef_mclasses.add(mclassdef.mclass)
+                               end
+                               local_mclasses.add(mclassdef.mclass)
+                       end
+               end
        end
 
        redef fun title do
-               if mbuilder.mmodule2nmodule.has_key(mmodule) then
+               if mbuilder.mmodule2nmodule.has_key(mmodule) and not mbuilder.mmodule2nmodule[mmodule].short_comment.is_empty then
                        var nmodule = mbuilder.mmodule2nmodule[mmodule]
-                       return "{mmodule.name} module | {nmodule.short_comment}"
+                       return "{mmodule.html_name} module | {nmodule.short_comment}"
                else
-                       return "{mmodule.name} module"
+                       return "{mmodule.html_name} module"
                end
        end
 
        redef fun menu do
                super
                append("<li><a href='index.html'>Overview</a></li>")
-               append("<li class='current'>{mmodule.name}</li>")
-               append("<li><a href='full-index.html'>Full Index</a></li>")
+               append("<li class='current'>{mmodule.html_name}</li>")
+               append("<li><a href='search.html'>Search</a></li>")
        end
 
        redef fun content do
-               sidebar
+               append("<div class='menu'>")
+               classes_column
+               importation_column
+               append("</div>")
                append("<div class='content'>")
-               append("<h1>{mmodule.name}</h1>")
-               append("<div class='subtitle'>{mmodule.html_signature(mbuilder)}</div>")
-               append(mmodule.html_full_comment(mbuilder))
-               process_generate_dot
-               classes
-               properties
+               module_doc
                append("</div>")
        end
 
-       private fun process_generate_dot do
-               var name = "dep_{mmodule.name}"
-               var op = new Buffer
-               op.append("digraph {name} \{ rankdir=BT; node[shape=none,margin=0,width=0,height=0,fontsize=10]; edge[dir=none,color=gray]; ranksep=0.2; nodesep=0.1;\n")
-               for m in mmodule.in_importation.poset do
-                       if m.name == "<main>" then continue
-                       var public_owner = m.public_owner
-                       if public_owner == null then
-                               public_owner = m
-                               if m == mmodule then
-                                       op.append("\"{m.name}\"[shape=box,margin=0.03];\n")
-                               else
-                                       op.append("\"{m.name}\"[URL=\"{m.url}\"];\n")
-                               end
-                       end
-                       for imported in m.in_importation.direct_greaters do
-                               if imported.name == "<main>" then continue
-                               if imported.public_owner == null then
-                                       op.append("\"{public_owner.name}\"->\"{imported.name}\";\n")
-                               end
-                       end
+       private fun classes_column do
+               var sorter = new MClassNameSorter
+               var sorted = new Array[MClass]
+               sorted.add_all(intro_mclasses)
+               sorted.add_all(redef_mclasses)
+               sorter.sort(sorted)
+               if not sorted.is_empty then
+                       append("<nav class='properties filterable'>")
+                       append("<h3>Classes</h3>")
+                       append("<h4>Classes</h4>")
+                       append("<ul>")
+                       for mclass in sorted do mclass.html_sidebar_item(self)
+                       append("</ul>")
+                       append("</nav>")
                end
-               op.append("\}\n")
-               generate_dot(op.to_s, name, "Dependency graph for module {mmodule.name}")
        end
 
-       private fun sidebar do
-               append("<div class='menu'>")
+       private fun importation_column do
                append("<nav>")
                append("<h3>Module Hierarchy</h3>")
                var dependencies = new Array[MModule]
                for dep in mmodule.in_importation.greaters do
-                       if dep == mmodule or dep.public_owner != null then continue
+                       if dep == mmodule or dep.direct_owner == mmodule or dep.public_owner == mmodule then continue
                        dependencies.add(dep)
                end
+               if mmodule.in_nesting.direct_greaters.length > 0 then
+                       append("<h4>Nested Modules</h4>")
+                       display_module_list(mmodule.in_nesting.direct_greaters.to_a)
+               end
                if dependencies.length > 0 then
                        append("<h4>All dependencies</h4>")
                        display_module_list(dependencies)
                end
                var clients = new Array[MModule]
                for dep in mmodule.in_importation.smallers do
-                       if dep == mmodule or dep.public_owner != null then continue
+                       if dep.name == "<main>" then continue
+                       if dep == mmodule then continue
                        clients.add(dep)
                end
                if clients.length > 0 then
@@ -591,82 +595,96 @@ class NitdocModule
                        display_module_list(clients)
                end
                append("</nav>")
-               if mmodule.in_nesting.direct_greaters.length > 0 then
-                       append("<nav>")
-                       append("<h3>Nested Modules</h3>")
-                       display_module_list(mmodule.in_nesting.direct_greaters.to_a)
-                       append("</nav>")
-               end
-               append("</div>")
        end
 
        private fun display_module_list(list: Array[MModule]) do
                append("<ul>")
-               var sorter = new ComparableSorter[MModule]
+               var sorter = new MModuleNameSorter
                sorter.sort(list)
-               for m in list do append("<li>{m.link(mbuilder)}</li>")
+               for m in list do
+                       append("<li>")
+                       m.html_link(self)
+                       append("</li>")
+               end
                append("</ul>")
        end
 
-       # display the class column
-       private fun classes do
-               var intro_mclasses = mmodule.intro_mclasses
-               var redef_mclasses = mmodule.redef_mclasses
-               var all_mclasses = new HashSet[MClass]
-               for m in mmodule.in_nesting.greaters do
-                       all_mclasses.add_all(m.intro_mclasses)
-                       all_mclasses.add_all(m.redef_mclasses)
+       private fun module_doc do
+               # title
+               append("<h1>{mmodule.html_name}</h1>")
+               append("<div class='subtitle info'>")
+               mmodule.html_signature(self)
+               append("</div>")
+               # comment
+               mmodule.html_comment(self)
+               process_generate_dot
+               # classes
+               var class_sorter = new MClassNameSorter
+               # intro
+               if not intro_mclasses.is_empty then
+                       var sorted = new Array[MClass]
+                       sorted.add_all(intro_mclasses)
+                       class_sorter.sort(sorted)
+                       append("<section class='classes'>")
+                       append("<h2 class='section-header'>Introduced classes</h2>")
+                       for mclass in sorted do mclass.html_full_desc(self)
+                       append("</section>")
                end
-               all_mclasses.add_all(intro_mclasses)
-               all_mclasses.add_all(redef_mclasses)
-
-               var sorted = new Array[MClass]
-               sorted.add_all(all_mclasses)
-               var sorter = new ComparableSorter[MClass]
-               sorter.sort(sorted)
-               append("<div class='module'>")
-               append("<article class='classes filterable'>")
-               append("<h2>Classes</h2>")
-               append("<ul>")
-               for c in sorted do
-                       if c.visibility < ctx.min_visibility then continue
-                       if redef_mclasses.has(c) and c.intro_mmodule.public_owner != mmodule then
-                               append("<li class='redef'>")
-                               append("<span title='refined in this module'>R </span>")
-                       else
-                               append("<li class='intro'>")
-                               append("<span title='introduced in this module'>I </span>")
-                       end
-                       append(c.link(mbuilder))
-                       append("</li>")
+               # redefs
+               var redefs = new Array[MClass]
+               for mclass in redef_mclasses do if not intro_mclasses.has(mclass) then redefs.add(mclass)
+               class_sorter.sort(redefs)
+               if not redefs.is_empty then
+                       append("<section class='classes'>")
+                       append("<h2 class='section-header'>Refined classes</h2>")
+                       for mclass in redefs do mclass.html_full_desc(self)
+                       append("</section>")
                end
-               append("</ul>")
-               append("</article>")
-               append("</div>")
        end
 
-       # display the property column
-       private fun properties do
-               # get properties
-               var mpropdefs = new HashSet[MPropDef]
-               for m in mmodule.in_nesting.greaters do
-                       for c in m.mclassdefs do mpropdefs.add_all(c.mpropdefs)
+       private fun process_generate_dot do
+               # build poset with public owners
+               var poset = new POSet[MModule]
+               for mmodule in self.mmodule.in_importation.poset do
+                       if mmodule.name == "<main>" then continue
+                       #if mmodule.public_owner != null then continue
+                       if not mmodule.in_importation < self.mmodule and not self.mmodule.in_importation < mmodule and mmodule != self.mmodule then continue
+                       poset.add_node(mmodule)
+                       for omodule in mmodule.in_importation.poset do
+                               if mmodule == omodule then continue
+                               if omodule.name == "<main>" then continue
+                               if not omodule.in_importation < self.mmodule and not self.mmodule.in_importation < omodule then continue
+                               if omodule.in_importation < mmodule then
+                                       poset.add_node(omodule)
+                                       poset.add_edge(omodule, mmodule)
+                               end
+                               if mmodule.in_importation < omodule then
+                                       poset.add_node(omodule)
+                                       poset.add_edge(mmodule, omodule)
+                               end
+                               #if omodule.public_owner != null then continue
+                               #if mmodule.in_importation < omodule then
+                                       #poset.add_node(omodule)
+                                       #poset.add_edge(mmodule, omodule)
+                               #end
+                       end
                end
-               for c in mmodule.mclassdefs do mpropdefs.add_all(c.mpropdefs)
-               var sorted = mpropdefs.to_a
-               var sorter = new ComparableSorter[MPropDef]
-               sorter.sort(sorted)
-               # display properties in one column
-               append("<article class='properties filterable'>")
-               append("<h2>Properties</h2>")
-               append("<ul>")
-               for mprop in sorted do
-                       if mprop isa MAttributeDef then continue
-                       if mprop.mproperty.visibility < ctx.min_visibility then continue
-                       append(mprop.html_list_item(mbuilder))
+               # build graph
+               var op = new Buffer
+               var name = "dep_{mmodule.name}"
+               op.append("digraph {name} \{ rankdir=BT; node[shape=none,margin=0,width=0,height=0,fontsize=10]; edge[dir=none,color=gray]; ranksep=0.2; nodesep=0.1;\n")
+               for mmodule in poset do
+                       if mmodule == self.mmodule then
+                               op.append("\"{mmodule.name}\"[shape=box,margin=0.03];\n")
+                       else
+                               op.append("\"{mmodule.name}\"[URL=\"{mmodule.url}\"];\n")
+                       end
+                       for omodule in poset[mmodule].direct_greaters do
+                               op.append("\"{mmodule.name}\"->\"{omodule.name}\";\n")
+                       end
                end
-               append("</ul>")
-               append("</article>")
+               op.append("\}\n")
+               generate_dot(op.to_s, name, "Dependency graph for module {mmodule.name}")
        end
 end
 
@@ -675,7 +693,6 @@ class NitdocClass
        super NitdocPage
 
        private var mclass: MClass
-       private var mbuilder: ModelBuilder
        private var vtypes = new HashSet[MVirtualTypeDef]
        private var consts = new HashSet[MMethodDef]
        private var meths = new HashSet[MMethodDef]
@@ -684,10 +701,10 @@ class NitdocClass
        init(mclass: MClass, ctx: NitdocContext, dot_dir: nullable String, source: nullable String) do
                super(ctx)
                self.mclass = mclass
-               self.mbuilder = ctx.modelbuilder
                self.dot_dir = dot_dir
                self.source = source
                # load properties
+               var locals = new HashSet[MProperty]
                for mclassdef in mclass.mclassdefs do
                        for mpropdef in mclassdef.mpropdefs do
                                if mpropdef.mproperty.visibility < ctx.min_visibility then continue
@@ -699,30 +716,38 @@ class NitdocClass
                                                meths.add(mpropdef)
                                        end
                                end
+                               locals.add(mpropdef.mproperty)
                        end
                end
                # get inherited properties
-               for mprop in mclass.inherited_mproperties do
-                       var mpropdef = mprop.intro
-                       if mprop.visibility < ctx.min_visibility then continue
-                       if mpropdef isa MVirtualTypeDef then vtypes.add(mpropdef)
-                       if mpropdef isa MMethodDef then
-                               if mpropdef.mproperty.is_init then
-                                       consts.add(mpropdef)
-                               else
-                                       meths.add(mpropdef)
+               for pclass in mclass.in_hierarchy(ctx.mainmodule).greaters do
+                       if pclass == mclass then continue
+                       for pclassdef in pclass.mclassdefs do
+                               for mprop in pclassdef.intro_mproperties do
+                                       var mpropdef = mprop.intro
+                                       if mprop.visibility < ctx.min_visibility then continue # skip if not correct visibiility
+                                       if locals.has(mprop) then continue # skip if local
+                                       if mclass.name != "Object" and mprop.intro_mclassdef.mclass.name == "Object" and (mprop.visibility <= protected_visibility or mprop.intro_mclassdef.mmodule.public_owner == null or mprop.intro_mclassdef.mmodule.public_owner.name != "standard") then continue # skip toplevels
+                                       if mpropdef isa MVirtualTypeDef then vtypes.add(mpropdef)
+                                       if mpropdef isa MMethodDef then
+                                               if mpropdef.mproperty.is_init then
+                                                       consts.add(mpropdef)
+                                               else
+                                                       meths.add(mpropdef)
+                                               end
+                                       end
+                                       inherited.add(mpropdef)
                                end
                        end
-                       inherited.add(mpropdef)
                end
        end
 
        redef fun title do
-               var nclass = mbuilder.mclassdef2nclassdef[mclass.intro]
+               var nclass = ctx.mbuilder.mclassdef2nclassdef[mclass.intro]
                if nclass isa AStdClassdef then
-                       return "{mclass.name} class | {nclass.short_comment}"
+                       return "{mclass.html_name} class | {nclass.short_comment}"
                else
-                       return "{mclass.name} class"
+                       return "{mclass.html_name} class"
                end
        end
 
@@ -731,12 +756,16 @@ class NitdocClass
                append("<li><a href='index.html'>Overview</a></li>")
                var public_owner = mclass.public_owner
                if public_owner is null then
-                       append("<li>{mclass.intro_mmodule.link(mbuilder)}</li>")
+                       append("<li>")
+                       mclass.intro_mmodule.html_link(self)
+                       append("</li>")
                else
-                       append("<li>{public_owner.link(mbuilder)}</li>")
+                       append("<li>")
+                       public_owner.html_link(self)
+                       append("</li>")
                end
-               append("<li class='current'>{mclass.name}</li>")
-               append("<li><a href='full-index.html'>Full Index</a></li>")
+               append("<li class='current'>{mclass.html_name}</li>")
+               append("<li><a href='search.html'>Search</a></li>")
        end
 
        redef fun content do
@@ -750,7 +779,7 @@ class NitdocClass
        end
 
        private fun properties_column do
-               var sorter = new ComparableSorter[MPropDef]
+               var sorter = new MPropDefNameSorter
                append("<nav class='properties filterable'>")
                append("<h3>Properties</h3>")
                # virtual types
@@ -761,7 +790,7 @@ class NitdocClass
                        append("<h4>Virtual Types</h4>")
                        append("<ul>")
                        for mprop in vts do
-                               append(mprop.html_sidebar_item(self))
+                               mprop.html_sidebar_item(self)
                        end
                        append("</ul>")
                end
@@ -773,7 +802,8 @@ class NitdocClass
                        append("<h4>Constructors</h4>")
                        append("<ul>")
                        for mprop in cts do
-                               append(mprop.html_sidebar_item(self))
+                               if mprop.mproperty.name == "init" and mprop.mclassdef.mclass != mclass then continue
+                               mprop.html_sidebar_item(self)
                        end
                        append("</ul>")
                end
@@ -785,8 +815,7 @@ class NitdocClass
                        append("<h4>Methods</h4>")
                        append("<ul>")
                        for mprop in mts do
-                               if mclass.name != "Object" and mprop.mproperty.intro_mclassdef.mclass.name == "Object" and mprop.mproperty.visibility <= protected_visibility then continue
-                               append(mprop.html_sidebar_item(self))
+                               mprop.html_sidebar_item(self)
                        end
                        append("</ul>")
                end
@@ -795,7 +824,7 @@ class NitdocClass
 
        private fun inheritance_column do
                var sorted = new Array[MClass]
-               var sorterp = new ComparableSorter[MClass]
+               var sorterp = new MClassNameSorter
                append("<nav>")
                append("<h3>Inheritance</h3>")
                var greaters = mclass.in_hierarchy(ctx.mainmodule).greaters.to_a
@@ -805,7 +834,9 @@ class NitdocClass
                        append("<ul>")
                        for sup in greaters do
                                if sup == mclass then continue
-                               append("<li>{sup.link(mbuilder)}</li>")
+                               append("<li>")
+                               sup.html_link(self)
+                               append("</li>")
                        end
                        append("</ul>")
                end
@@ -819,7 +850,9 @@ class NitdocClass
                        append("<ul>")
                        for sub in smallers do
                                if sub == mclass then continue
-                               append("<li>{sub.link(mbuilder)}</li>")
+                               append("<li>")
+                               sub.html_link(self)
+                               append("</li>")
                        end
                        append("</ul>")
                else if direct_smallers.length <= 100 then
@@ -828,7 +861,9 @@ class NitdocClass
                        append("<ul>")
                        for sub in direct_smallers do
                                if sub == mclass then continue
-                               append("<li>{sub.link(mbuilder)}</li>")
+                               append("<li>")
+                               sub.html_link(self)
+                               append("</li>")
                        end
                        append("</ul>")
                else
@@ -839,17 +874,15 @@ class NitdocClass
 
        private fun class_doc do
                # title
-               append("<h1>{mclass.html_signature}</h1>")
-               append("<div class='subtitle info'>{mclass.html_full_signature(mbuilder)}")
-
-               append("</div>")
+               append("<h1>{mclass.html_name}{mclass.html_short_signature}</h1>")
+               append("<div class='subtitle info'>")
+               if mclass.visibility < public_visibility then append("{mclass.visibility.to_s} ")
+               append("{mclass.kind.to_s} ")
+               mclass.html_namespace(self)
+               append("{mclass.html_short_signature}</div>")
                # comment
-               var nclass = mbuilder.mclassdef2nclassdef[mclass.intro]
-               append("<div style=\"float: right;\"><a id=\"lblDiffCommit\"></a></div>")
-               append("<section class='description'>")
-               if nclass isa AStdClassdef and not nclass.comment.is_empty then append("<pre class=\"text_label\" title=\"122\" name=\"\" tag=\"{mclass.mclassdefs.first.location.to_s}\" type=\"2\">{nclass.comment}</pre><textarea id=\"fileContent\" class=\"edit\" cols=\"76\" rows=\"1\" style=\"display: none;\"></textarea><a id=\"cancelBtn\" style=\"display: none;\">Cancel</a><a id=\"commitBtn\" style=\"display: none;\">Commit</a><pre id=\"preSave\" class=\"text_label\" type=\"2\"></pre>")
+               mclass.html_comment(self)
                process_generate_dot
-               append("</section>")
                # concerns
                var concern2meths = new ArrayMap[MModule, Array[MMethodDef]]
                var sorted_meths = new Array[MMethodDef]
@@ -876,21 +909,21 @@ class NitdocClass
                append("<h2 class='section-header'>Concerns</h2>")
                append("<ul>")
                for owner, mmodules in sections do
-                       var nowner = mbuilder.mmodule2nmodule[owner]
+                       var nowner = ctx.mbuilder.mmodule2nmodule[owner]
                        append("<li>")
                        if nowner.short_comment.is_empty then
-                               append("<a href=\"#{owner.anchor}\">{owner.name}</a>")
+                               append("<a href=\"#{owner.anchor}\">{owner.html_name}</a>")
                        else
-                               append("<a href=\"#{owner.anchor}\">{owner.name}</a>: {nowner.short_comment}")
+                               append("<a href=\"#{owner.anchor}\">{owner.html_name}</a>: {nowner.short_comment}")
                        end
                        if not mmodules.is_empty then
                                append("<ul>")
                                for mmodule in mmodules do
-                                       var nmodule = mbuilder.mmodule2nmodule[mmodule]
+                                       var nmodule = ctx.mbuilder.mmodule2nmodule[mmodule]
                                        if nmodule.short_comment.is_empty then
-                                               append("<li><a href=\"#{mmodule.anchor}\">{mmodule.name}</a></li>")
+                                               append("<li><a href=\"#{mmodule.anchor}\">{mmodule.html_name}</a></li>")
                                        else
-                                               append("<li><a href=\"#{mmodule.anchor}\">{mmodule.name}</a>: {nmodule.short_comment}</li>")
+                                               append("<li><a href=\"#{mmodule.anchor}\">{mmodule.html_name}</a>: {nmodule.short_comment}</li>")
                                        end
                                end
                                append("</ul>")
@@ -900,10 +933,9 @@ class NitdocClass
                append("</ul>")
                append("</section>")
                # properties
-               var prop_sorter = new ComparableSorter[MPropDef]
-               var sorterprop = new ComparableSorter[MProperty]
-               var sorterc = new ComparableSorter[MClass]
+               var prop_sorter = new MPropDefNameSorter
                var lmmodule = new List[MModule]
+               var nclass = ctx.mbuilder.mclassdef2nclassdef[mclass.intro]
                # virtual and formal types
                var local_vtypes = new Array[MVirtualTypeDef]
                for vt in vtypes do if not inherited.has(vt) then local_vtypes.add(vt)
@@ -914,14 +946,16 @@ class NitdocClass
                        if mclass.arity > 0 and nclass isa AStdClassdef then
                                for ft, bound in mclass.parameter_types do
                                        append("<article id='FT_{ft}'>")
-                                       append("<h3 class='signature'>{ft}: {bound.link(mbuilder)}</h3>")
+                                       append("<h3 class='signature' data-untyped-signature='{ft.to_s}'><span>{ft}: ")
+                                       bound.html_link(self)
+                                       append("</span></h3>")
                                        append("<div class=\"info\">formal generic type</div>")
                                        append("</article>")
                                end
                        end
                        # virtual types
                        prop_sorter.sort(local_vtypes)
-                       for prop in local_vtypes do append(prop.html_full_desc(self))
+                       for prop in local_vtypes do prop.html_full_desc(self, self.mclass)
                        append("</section>")
                end
                # constructors
@@ -931,7 +965,7 @@ class NitdocClass
                if local_consts.length > 0 then
                        append("<section class='constructors'>")
                        append("<h2 class='section-header'>Constructors</h2>")
-                       for prop in local_consts do append(prop.html_full_desc(self))
+                       for prop in local_consts do prop.html_full_desc(self, self.mclass)
                        append("</section>")
                end
                # methods
@@ -941,34 +975,39 @@ class NitdocClass
                        for owner, mmodules in sections do
                                append("<a id=\"{owner.anchor}\"></a>")
                                if owner != mclass.intro_mmodule and owner != mclass.public_owner then
-                                       var nowner = mbuilder.mmodule2nmodule[owner]
-                                       append("<h3 class=\"concern-toplevel\">Methods refined in {owner.link(mbuilder)}</h3>")
-                                       if nowner.short_comment.is_empty then
-                                               append("<p class=\"concern-doc\">{owner.link(mbuilder)}</p>")
-                                       else
-                                               append("<p class=\"concern-doc\">{owner.link(mbuilder)}: {nowner.short_comment}</p>")
+                                       var nowner = ctx.mbuilder.mmodule2nmodule[owner]
+                                       append("<h3 class=\"concern-toplevel\">Methods refined in ")
+                                       owner.html_link(self)
+                                       append("</h3>")
+                                       append("<p class=\"concern-doc\">")
+                                       owner.html_link(self)
+                                       if not nowner.short_comment.is_empty then
+                                               append(": {nowner.short_comment}")
                                        end
+                                       append("</p>")
                                end
                                if concern2meths.has_key(owner) then
                                        var mmethods = concern2meths[owner]
                                        prop_sorter.sort(mmethods)
-                                       for prop in mmethods do append(prop.html_full_desc(self))
+                                       for prop in mmethods do prop.html_full_desc(self, self.mclass)
                                end
                                for mmodule in mmodules do
                                        append("<a id=\"{mmodule.anchor}\"></a>")
-                                       var nmodule = mbuilder.mmodule2nmodule[mmodule]
+                                       var nmodule = ctx.mbuilder.mmodule2nmodule[mmodule]
                                        if mmodule != mclass.intro_mmodule and mmodule != mclass.public_owner then
-                                               if nmodule.short_comment.is_empty then
-                                                       append("<p class=\"concern-doc\">{mmodule.link(mbuilder)}</p>")
-                                               else
-                                                       append("<p class=\"concern-doc\">{mmodule.link(mbuilder)}: {nmodule.short_comment}</p>")
+                                               append("<p class=\"concern-doc\">")
+                                               mmodule.html_link(self)
+                                               if not nmodule.short_comment.is_empty then
+                                                       append(": {nmodule.short_comment}")
                                                end
+                                               append("</p>")
                                        end
                                        var mmethods = concern2meths[mmodule]
                                        prop_sorter.sort(mmethods)
-                                       for prop in mmethods do append(prop.html_full_desc(self))
+                                       for prop in mmethods do prop.html_full_desc(self, self.mclass)
                                end
                        end
+                       append("</section>")
                end
                # inherited properties
                if inherited.length > 0 then
@@ -981,19 +1020,22 @@ class NitdocClass
                                if not classes.has_key(mclass) then classes[mclass] = new Array[MPropDef]
                                classes[mclass].add(mmethod)
                        end
-                       append("<h3>Inherited Properties</h3>")
+                       append("<section class='inherited'>")
+                       append("<h2 class='section-header'>Inherited Properties</h2>")
                        for c, mmethods in classes do
                                prop_sorter.sort(mmethods)
-                               append("<p>Defined in {c.link(mbuilder)}: ")
+                               append("<p>Defined in ")
+                               c.html_link(self)
+                               append(": ")
                                for i in [0..mmethods.length[ do
                                        var mmethod = mmethods[i]
-                                       append(mmethod.link(mbuilder))
+                                       mmethod.html_link(self)
                                        if i <= mmethods.length - 1 then append(", ")
                                end
                                append("</p>")
                        end
+                       append("</section>")
                end
-               append("</section>")
        end
 
        private fun process_generate_dot do
@@ -1048,570 +1090,724 @@ end
 #
 
 redef class MModule
-       super Comparable
-       redef type OTHER: MModule
-       redef fun <(other: OTHER): Bool do return self.name < other.name
-
-       # Get the list of all methods in a module
-       fun imported_methods: Set[MMethod] do
-               var methods = new HashSet[MMethod]
-               for mclass in imported_mclasses do
-                       for method in mclass.intro_methods do
-                               methods.add(method)
-                       end
-               end
-               return methods
-       end
-
-       # Get the list aof all refined methods in a module
-       fun redef_methods: Set[MMethod] do
-               var methods = new HashSet[MMethod]
-               for mclass in redef_mclasses do
-                       for method in mclass.intro_methods do
-                               methods.add(method)
-                       end
-               end
-               return methods
-       end
+       # Return the HTML escaped name of the module
+       private fun html_name: String do return name.html_escape
 
        # URL to nitdoc page
-       fun url: String do
-               var res = new Buffer
-               res.append("module_")
-               var mowner = public_owner
-               if mowner != null then
-                       res.append("{public_owner.name}_")
-               end
-               res.append("{self.name}.html")
-               return res.to_s
-       end
-
-       # html anchor id to the module in a nitdoc page
-       fun anchor: String do
-               var res = new Buffer
-               res.append("MOD_")
-               var mowner = public_owner
-               if mowner != null then
-                       res.append("{public_owner.name}_")
+       #       module_owner_name.html
+       private fun url: String do
+               if url_cache == null then
+                       var res = new Buffer
+                       res.append("module_")
+                       var mowner = public_owner
+                       if mowner != null then
+                               res.append("{public_owner.name}_")
+                       end
+                       res.append("{self.name}.html")
+                       url_cache = res.to_s
+               end
+               return url_cache.as(not null)
+       end
+       private var url_cache: nullable String
+
+       # html anchor id for the module in a nitdoc page
+       #       MOD_owner_name
+       private fun anchor: String do
+               if anchor_cache == null then
+                       var res = new Buffer
+                       res.append("MOD_")
+                       var mowner = public_owner
+                       if mowner != null then
+                               res.append("{public_owner.name}_")
+                       end
+                       res.append(self.name)
+                       anchor_cache = res.to_s
                end
-               res.append(self.name)
-               return res.to_s
+               return anchor_cache.as(not null)
        end
+       private var anchor_cache: nullable String
 
        # Return a link (html a tag) to the nitdoc module page
-       fun link(mbuilder: ModelBuilder): String do
-               if mbuilder.mmodule2nmodule.has_key(self) then
-                       return "<a href='{url}' title='{mbuilder.mmodule2nmodule[self].short_comment}'>{name}</a>"
-               else
-                       return "<a href='{url}'>{name}</a>"
+       #       <a href="url" title="short_comment">html_name</a>
+       private fun html_link(page: NitdocPage) do
+               if html_link_cache == null then
+                       var res = new Buffer
+                       if page.ctx.mbuilder.mmodule2nmodule.has_key(self) then
+                               res.append("<a href='{url}' title='{page.ctx.mbuilder.mmodule2nmodule[self].short_comment}'>{html_name}</a>")
+                       else
+                               res.append("<a href='{url}'>{html_name}</a>")
+                       end
+                       html_link_cache = res.to_s
                end
+               page.append(html_link_cache.as(not null))
        end
+       private var html_link_cache: nullable String
 
        # Return the module signature decorated with html
-       fun html_signature(mbuilder: ModelBuilder): String do
-               return "<span>module {html_full_namespace(mbuilder)}</span>"
+       #       <span>module html_full_namespace</span>
+       private fun html_signature(page: NitdocPage) do
+               page.append("<span>module ")
+               html_full_namespace(page)
+               page.append("</span>")
        end
 
        # Return the module full namespace decorated with html
-       fun html_full_namespace(mbuilder: ModelBuilder): String do
-               var res = new Buffer
-               res.append("<span>")
+       #       <span>public_owner.html_namespace::html_link</span>
+       private fun html_full_namespace(page: NitdocPage) do
+               page.append("<span>")
                var mowner = public_owner
                if mowner != null then
-                       res.append(public_owner.html_namespace(mbuilder))
-                       res.append("::")
+                       public_owner.html_namespace(page)
+                       page.append("::")
                end
-               res.append(self.link(mbuilder))
-               res.append("</span>")
-               return res.to_s
+               html_link(page)
+               page.append("</span>")
        end
 
        # Return the module full namespace decorated with html
-       fun html_namespace(mbuilder: ModelBuilder): String do
-               var res = new Buffer
-               res.append("<span>")
+       #       <span>public_owner.html_namespace</span>
+       private fun html_namespace(page: NitdocPage) do
+               page.append("<span>")
                var mowner = public_owner
                if mowner != null then
-                       res.append(public_owner.html_namespace(mbuilder))
+                       public_owner.html_namespace(page)
                else
-                       res.append(self.link(mbuilder))
+                       html_link(page)
                end
-               res.append("</span>")
-               return res.to_s
+               page.append("</span>")
        end
 
        # Return the full comment of the module decorated with html
-       fun html_full_comment(mbuilder: ModelBuilder): String do
-               var res = new Buffer
-               if mbuilder.mmodule2nmodule.has_key(self) then
-                       res.append("<div id='description'>")
-                       res.append("<pre class='text_label'>{mbuilder.mmodule2nmodule[self].comment}</pre>")
-                       res.append("<textarea class='edit' rows='1' cols='76' id='fileContent'></textarea>")
-                       res.append("<a id='cancelBtn'>Cancel</a>")
-                       res.append("<a id='commitBtn'>Commit</a>")
-                       res.append("<pre class='text_label' id='preSave' type='2'></pre>")
-                       res.append("</div>")
+       private fun html_comment(page: NitdocPage) do
+               page.append("<div class='description'>")
+               if page.ctx.mbuilder.mmodule2nmodule.has_key(self) then
+                       var nmodule = page.ctx.mbuilder.mmodule2nmodule[self]
+                       page.append("<textarea class='baseComment' data-comment-namespace='{full_name}' data-comment-location='{nmodule.doc_location.to_s}'>{nmodule.full_comment}</textarea>")
+                       if nmodule.full_comment == "" then
+                               page.append("<p class='info inheritance'>")
+                               page.append("<span class=\"noComment\">no comment for </span>")
+                       else
+                               page.append("<div class='comment'>{nmodule.full_markdown}</div>")
+                               page.append("<p class='info inheritance'>")
+                       end
+                       page.append("definition in ")
+                       self.html_full_namespace(page)
+                       page.append(" {page.show_source(nmodule.location)}</p>")
                end
-               return res.to_s
+               page.append("</div>")
+       end
+
+       private fun has_mclassdef_for(mclass: MClass): Bool do
+               for mmodule in self.in_nesting.greaters do
+                       for mclassdef in mmodule.mclassdefs do
+                               if mclassdef.mclass == mclass then return true
+                       end
+               end
+               return false
+       end
+
+       private fun has_mclassdef(mclassdef: MClassDef): Bool do
+               for mmodule in self.in_nesting.greaters do
+                       for oclassdef in mmodule.mclassdefs do
+                               if mclassdef == oclassdef then return true
+                       end
+               end
+               return false
        end
 end
 
 redef class MClass
-       super Comparable
-       redef type OTHER: MClass
-       redef fun <(other: OTHER): Bool do return self.name < other.name
+       # Return the HTML escaped name of the module
+       private fun html_name: String do return name.html_escape
 
-       # Return the module signature decorated with html
-       fun html_full_signature(mbuilder: ModelBuilder): String do
-               var res = new Buffer
-               if visibility < public_visibility then res.append("{visibility.to_s} ")
-               res.append("{kind} {html_namespace(mbuilder)}")
-               return res.to_s
+       # URL to nitdoc page
+       #       class_owner_name.html
+       private fun url: String do
+               return "class_{public_owner}_{name}.html"
+       end
+
+       # html anchor id for the class in a nitdoc page
+       #       MOD_owner_name
+       private fun anchor: String do
+               if anchor_cache == null then
+                       anchor_cache = "CLASS_{public_owner.name}_{name}"
+               end
+               return anchor_cache.as(not null)
+       end
+       private var anchor_cache: nullable String
+
+       # Return a link (with signature) to the nitdoc class page
+       #       <a href="url" title="short_comment">html_name(signature)</a>
+       private fun html_link(page: NitdocPage) do
+               if html_link_cache == null then
+                       var res = new Buffer
+                       res.append("<a href='{url}'")
+                       if page.ctx.mbuilder.mclassdef2nclassdef.has_key(intro) then
+                               var nclass = page.ctx.mbuilder.mclassdef2nclassdef[intro]
+                               if nclass isa AStdClassdef then
+                                       res.append(" title=\"{nclass.short_comment}\"")
+                               end
+                       end
+                       res.append(">{html_name}{html_short_signature}</a>")
+                       html_link_cache = res.to_s
+               end
+               page.append(html_link_cache.as(not null))
+       end
+       private var html_link_cache: nullable String
+
+       # Return a short link (without signature) to the nitdoc class page
+       #       <a href="url" title="short_comment">html_name</a>
+       private fun html_short_link(page: NitdocPage) do
+               if html_short_link_cache == null then
+                       var res = new Buffer
+                       res.append("<a href='{url}'")
+                       if page.ctx.mbuilder.mclassdef2nclassdef.has_key(intro) then
+                               var nclass = page.ctx.mbuilder.mclassdef2nclassdef[intro]
+                               if nclass isa AStdClassdef then
+                                       res.append(" title=\"{nclass.short_comment}\"")
+                               end
+                       end
+                       res.append(">{html_name}</a>")
+                       html_short_link_cache = res.to_s
+               end
+               page.append(html_short_link_cache.as(not null))
+       end
+       private var html_short_link_cache: nullable String
+
+       # Return a link (with signature) to the class anchor
+       #       <a href="url" title="short_comment">html_name</a>
+       private fun html_link_anchor(page: NitdocPage) do
+               if html_link_anchor_cache == null then
+                       var res = new Buffer
+                       res.append("<a href='#{anchor}'")
+                       if page.ctx.mbuilder.mclassdef2nclassdef.has_key(intro) then
+                               var nclass = page.ctx.mbuilder.mclassdef2nclassdef[intro]
+                               if nclass isa AStdClassdef then
+                                       res.append(" title=\"{nclass.short_comment}\"")
+                               end
+                       end
+                       res.append(">{html_name}{html_short_signature}</a>")
+                       html_link_anchor_cache = res.to_s
+               end
+               page.append(html_link_anchor_cache.as(not null))
        end
+       private var html_link_anchor_cache: nullable String
 
-       # Add type parameters
-       fun html_signature: String do
+       # Return the generic signature of the class with bounds
+       #       [E: <a>MType</a>, F: <a>MType</a>]
+       private fun html_signature(page: NitdocPage) do
                if arity > 0 then
-                       return "{name}[{intro.parameter_names.join(", ")}]"
-               else
-                       return name
+                       page.append("[")
+                       for i in [0..intro.parameter_names.length[ do
+                               page.append("{intro.parameter_names[i]}: ")
+                               intro.bound_mtype.arguments[i].html_link(page)
+                               if i < intro.parameter_names.length - 1 then page.append(", ")
+                       end
+                       page.append("]")
                end
        end
 
-       # Return a link (html a tag) to the nitdoc class page
-       fun link(mbuilder: ModelBuilder): String do
-               if mbuilder.mclassdef2nclassdef.has_key(intro) then
-                       var nclass = mbuilder.mclassdef2nclassdef[intro]
-                       if nclass isa AStdClassdef then
-                               return "<a href='{url}' title=\"{nclass.short_comment}\">{html_signature}</a>"
-                       else
-                               return "<a href='{url}'>{html_signature}</a>"
-                       end
+       # Return the generic signature of the class without bounds
+       #       [E, F]
+       private fun html_short_signature: String do
+               if arity > 0 then
+                       return "[{intro.parameter_names.join(", ")}]"
                else
-                       return "<a href='{url}'>{html_signature}</a>"
+                       return ""
                end
        end
 
        # Return the class namespace decorated with html
-       fun html_namespace(mbuilder: ModelBuilder): String do
-               var res = new Buffer
-               res.append(intro_mmodule.html_namespace(mbuilder))
-               res.append("::<span>{self.link(mbuilder)}</span>")
-               return res.to_s
+       #       <span>intro_module::html_short_link</span>
+       private fun html_namespace(page: NitdocPage) do
+               intro_mmodule.html_namespace(page)
+               page.append("::<span>")
+               html_short_link(page)
+               page.append("</span>")
+       end
+
+       # Return a list item for the mclass
+       #       <li>html_link</li>
+       private fun html_sidebar_item(page: NitdocModule) do
+               if page.mmodule.in_nesting.greaters.has(intro.mmodule) then
+                       page.append("<li class='intro'>")
+                       page.append("<span title='Introduced'>I</span>")
+                       html_link_anchor(page)
+               else if page.mmodule.has_mclassdef_for(self) then
+                       page.append("<li class='redef'>")
+                       page.append("<span title='Redefined'>R</span>")
+                       html_link_anchor(page)
+               else
+                       page.append("<li class='inherit'>")
+                       page.append("<span title='Inherited'>H</span>")
+                       html_link(page)
+               end
+               page.append("</li>")
+       end
+
+       private fun html_full_desc(page: NitdocModule) do
+               var is_redef = not page.mmodule.in_nesting.greaters.has(intro.mmodule)
+               var redefs = mpropdefs_in_module(page)
+               if not is_redef or not redefs.is_empty then
+                       var classes = new Array[String]
+                       classes.add(kind.to_s)
+                       if is_redef then classes.add("redef")
+                       classes.add(visibility.to_s)
+                       page.append("<article class='{classes.join(" ")}' id='{anchor}'>")
+                       page.append("<h3 class='signature' data-untyped-signature='{html_name}{html_short_signature}'>")
+                       page.append("<span>")
+                       html_short_link(page)
+                       html_signature(page)
+                       page.append("</span></h3>")
+                       html_info(page)
+                       html_comment(page)
+                       page.append("</article>")
+               end
+       end
+
+       private fun html_info(page: NitdocModule) do
+               page.append("<div class='info'>")
+               if visibility < public_visibility then page.append("{visibility.to_s} ")
+               if not page.mmodule.in_nesting.greaters.has(intro.mmodule) then page.append("redef ")
+               page.append("{kind} ")
+               html_namespace(page)
+               page.append("{html_short_signature}</div>")
+       end
+
+       private fun html_comment(page: NitdocPage) do
+               page.append("<div class='description'>")
+               if page isa NitdocModule then
+                       page.mmodule.linearize_mclassdefs(mclassdefs)
+                       # comments for each mclassdef contained in current mmodule
+                       for mclassdef in mclassdefs do
+                               if not mclassdef.is_intro and not page.mmodule.mclassdefs.has(mclassdef) then continue
+                               if page.ctx.mbuilder.mclassdef2nclassdef.has_key(mclassdef) then
+                                       var nclass = page.ctx.mbuilder.mclassdef2nclassdef[mclassdef]
+                                       if nclass isa AStdClassdef then
+                                               page.append("<textarea class='baseComment' data-comment-namespace='{mclassdef.mmodule.full_name}::{name}' data-comment-location='{nclass.doc_location.to_s}'>{nclass.full_comment}</textarea>")
+                                               if nclass.full_comment == "" then
+                                                       page.append("<p class='info inheritance'>")
+                                                       page.append("<span class=\"noComment\">no comment for </span>")
+                                               else
+                                                       page.append("<div class='comment'>{nclass.full_markdown}</div>")
+                                                       page.append("<p class='info inheritance'>")
+                                               end
+                                               if mclassdef.is_intro then
+                                                       page.append("introduction in ")
+                                               else
+                                                       page.append("refinement in ")
+                                               end
+                                               mclassdef.mmodule.html_full_namespace(page)
+                                               page.append(" {page.show_source(nclass.location)}</p>")
+                                       end
+                               end
+                       end
+               else
+                       # comments for intro
+                       if page.ctx.mbuilder.mclassdef2nclassdef.has_key(intro) then
+                               var nclass = page.ctx.mbuilder.mclassdef2nclassdef[intro]
+                               if nclass isa AStdClassdef then
+                                       page.append("<textarea class='baseComment' data-comment-namespace='{intro.mmodule.full_name}::{name}' data-comment-location='{nclass.doc_location.to_s}'>{nclass.full_comment}</textarea>")
+                                       if nclass.full_comment == "" then
+                                               page.append("<p class='info inheritance'>")
+                                               page.append("<span class=\"noComment\">no comment for </span>")
+                                       else
+                                               page.append("<div class='comment'>{nclass.full_markdown}</div>")
+                                               page.append("<p class='info inheritance'>")
+                                       end
+                                       page.append("introduction in ")
+                                       intro.mmodule.html_full_namespace(page)
+                                       page.append(" {page.show_source(nclass.location)}</p>")
+                               end
+                       end
+               end
+               page.append("</div>")
        end
 
-       fun url: String do
-               return "class_{public_owner}_{c_name}.html"
+       private fun mpropdefs_in_module(page: NitdocModule): Array[MPropDef] do
+               var res = new Array[MPropDef]
+               page.mmodule.linearize_mclassdefs(mclassdefs)
+               for mclassdef in mclassdefs do
+                       if not page.mmodule.mclassdefs.has(mclassdef) then continue
+                       if mclassdef.is_intro then continue
+                       for mpropdef in mclassdef.mpropdefs do
+                               if mpropdef.mproperty.visibility < page.ctx.min_visibility then continue
+                               if mpropdef isa MAttributeDef then continue
+                               res.add(mpropdef)
+                       end
+               end
+               return res
        end
-
-       # Escape name for html output
-       redef fun name do return super.html_escape
 end
 
 redef class MProperty
-       super Comparable
-       redef type OTHER: MProperty
-       redef fun <(other: OTHER): Bool do return self.name < other.name
+       # Escape name for html output
+       private fun html_name: String do return name.html_escape
 
        # Return the property namespace decorated with html
-       fun html_namespace(mbuilder: ModelBuilder): String do
-               return "{intro_mclassdef.mclass.html_namespace(mbuilder)}::<span>{intro.link(mbuilder)}</span>"
+       #       <span>intro_module::intro_class::html_link</span>
+       private fun html_namespace(page: NitdocPage) do
+               intro_mclassdef.mclass.html_namespace(page)
+               page.append(intro_mclassdef.mclass.html_short_signature)
+               page.append("::<span>")
+               intro.html_link(page)
+               page.append("</span>")
        end
-
-       # Escape name for html output
-       redef fun name do return super.html_escape
 end
 
 redef class MType
-       fun link(mbuilder: ModelBuilder): String is abstract
+       # Link to the type definition in the nitdoc page
+       private fun html_link(page: NitdocPage) is abstract
 end
 
 redef class MClassType
-       redef fun link(mbuilder) do return mclass.link(mbuilder)
+       redef fun html_link(page) do mclass.html_link(page)
 end
 
 redef class MNullableType
-       redef fun link(mbuilder) do return "nullable {mtype.link(mbuilder)}"
+       redef fun html_link(page) do
+               page.append("nullable ")
+               mtype.html_link(page)
+       end
 end
 
 redef class MGenericType
-       redef fun link(mbuilder) do
-               var res = new Buffer
-               res.append("<a href='{mclass.url}'>{mclass.name}</a>[")
+       redef fun html_link(page) do
+               page.append("<a href='{mclass.url}'>{mclass.html_name}</a>[")
                for i in [0..arguments.length[ do
-                       res.append(arguments[i].link(mbuilder))
-                       if i < arguments.length - 1 then res.append(", ")
+                       arguments[i].html_link(page)
+                       if i < arguments.length - 1 then page.append(", ")
                end
-               res.append("]")
-               return res.to_s
+               page.append("]")
        end
 end
 
 redef class MParameterType
-       redef fun link(mbuilder) do
+       redef fun html_link(page) do
                var name = mclass.intro.parameter_names[rank]
-               return "<a href='{mclass.url}#FT_{name}' title='formal type'>{name}</a>"
+               page.append("<a href='{mclass.url}#FT_{name}' title='formal type'>{name}</a>")
        end
 end
 
 redef class MVirtualType
-       redef fun link(mbuilder) do return mproperty.intro.link(mbuilder)
+       redef fun html_link(page) do mproperty.intro.html_link(page)
 end
 
 redef class MClassDef
        # Return the classdef namespace decorated with html
-       fun html_namespace(mbuilder: ModelBuilder): String do
-               var res = new Buffer
-               res.append(mmodule.html_full_namespace(mbuilder))
-               res.append("::<span>{self.mclass.link(mbuilder)}</span>")
-               return res.to_s
+       private fun html_namespace(page: NitdocPage) do
+               mmodule.html_full_namespace(page)
+               page.append("::<span>")
+               mclass.html_link(page)
+               page.append("</span>")
        end
 end
 
 redef class MPropDef
-       super Comparable
-       redef type OTHER: MPropDef
-       redef fun <(other: OTHER): Bool do return self.mproperty.name < other.mproperty.name
-
-       fun url: String do return "{mclassdef.mclass.url}#{anchor}"
-       fun anchor: String do return "PROP_{mclassdef.mclass.public_owner.name}_{c_name}"
-
-       # Return a link (html a tag) to the nitdoc class page
-       fun link(mbuilder: ModelBuilder): String do
-               if mbuilder.mpropdef2npropdef.has_key(self) then
-                       var nprop = mbuilder.mpropdef2npropdef[self]
-                       return "<a href=\"{url}\" title=\"{nprop.short_comment}\">{mproperty.name}</a>"
-               else
-                       return "<a href=\"{url}\">{mproperty.name}</a>"
+       # Return the full qualified name of the mpropdef
+       #       module::classdef::name
+       private fun full_name: String do
+               return "{mclassdef.mclass.public_owner.name}::{mclassdef.mclass.name}::{mproperty.name}"
+       end
+
+       # URL into the nitdoc page
+       #       class_owner_name.html#anchor
+       private fun url: String do
+               if url_cache == null then
+                       url_cache = "{mclassdef.mclass.url}#{anchor}"
                end
+               return url_cache.as(not null)
        end
+       private var url_cache: nullable String
 
-       # Return a list item for the mpropdef
-       fun html_list_item(mbuilder: ModelBuilder): String do
-               var res = new Buffer
-               if is_intro then
-                       res.append("<li class='intro'>")
-                       res.append("<span title='introduction'>I</span>&nbsp;{link(mbuilder)} ({mclassdef.mclass.link(mbuilder)})")
-                       res.append("</li>")
-               else
-                       res.append("<li class='redef'>")
-                       res.append("<span title='redefinition'>R</span>&nbsp;{link(mbuilder)} ({mclassdef.mclass.link(mbuilder)})")
-                       res.append("</li>")
+       # html anchor id for the property in a nitdoc class page
+       #       PROP_mclass_propertyname
+       private fun anchor: String do
+               if anchor_cache == null then
+                       anchor_cache = "PROP_{mclassdef.mclass.public_owner.name}_{mproperty.name.replace(" ", "_")}"
                end
-               return res.to_s
+               return anchor_cache.as(not null)
        end
+       private var anchor_cache: nullable String
+
+       # Return a link to property into the nitdoc class page
+       #       <a href="url" title="short_comment">html_name</a>
+       private fun html_link(page: NitdocPage) do
+               if html_link_cache == null then
+                       var res = new Buffer
+                       if page.ctx.mbuilder.mpropdef2npropdef.has_key(self) then
+                               var nprop = page.ctx.mbuilder.mpropdef2npropdef[self]
+                               res.append("<a href=\"{url}\" title=\"{nprop.short_comment}\">{mproperty.html_name}</a>")
+                       else
+                               res.append("<a href=\"{url}\">{mproperty.html_name}</a>")
+                       end
+                       html_link_cache = res.to_s
+               end
+               page.append(html_link_cache.as(not null))
+       end
+       private var html_link_cache: nullable String
 
        # Return a list item for the mpropdef
-       fun html_sidebar_item(page: NitdocClass): String do
-               var res = new Buffer
+       #       <li>html_link</li>
+       private fun html_sidebar_item(page: NitdocClass) do
                if is_intro and mclassdef.mclass == page.mclass then
-                       res.append("<li class='intro'>")
-                       res.append("<span title='Introduced'>I</span>")
+                       page.append("<li class='intro'>")
+                       page.append("<span title='Introduced'>I</span>")
                else if is_intro and mclassdef.mclass != page.mclass then
-                       res.append("<li class='inherit'>")
-                       res.append("<span title='Inherited'>H</span>")
+                       page.append("<li class='inherit'>")
+                       page.append("<span title='Inherited'>H</span>")
                else
-                       res.append("<li class='redef'>")
-                       res.append("<span title='Redefined'>R</span>")
+                       page.append("<li class='redef'>")
+                       page.append("<span title='Redefined'>R</span>")
                end
-               res.append(link(page.mbuilder))
-               res.append("</li>")
-               return res.to_s
+               html_link(page)
+               page.append("</li>")
        end
 
-       fun html_full_desc(page: NitdocClass): String is abstract
-       fun html_info(page: NitdocClass): String is abstract
-
-       fun full_name: String do
-               return "{mclassdef.mclass.public_owner.name}::{mclassdef.mclass.name}::{mproperty.name}"
-       end
+       private fun html_full_desc(page: NitdocPage, ctx: MClass) is abstract
+       private fun html_info(page: NitdocPage, ctx: MClass) is abstract
 
-       fun html_inheritance(page: NitdocClass): String do
-               var res = new Buffer
-               # definitions block
-               res.append("<p class='info'>")
-               page.ctx.mainmodule.linearize_mpropdefs(mproperty.mpropdefs)
-               var previous_defs = new Array[MPropDef]
-               var next_defs = new Array[MPropDef]
-               var self_passed = false
-               for def in mproperty.mpropdefs do
-                       if def == self then
-                               self_passed = true
-                               continue
-                       end
-                       if not self_passed then
-                               if def.mclassdef.mclass.in_hierarchy(page.ctx.mainmodule) < page.mclass then continue
-                               if def.is_intro then continue
-                               previous_defs.add(def)
-                       else
-                               if page.mclass.in_hierarchy(page.ctx.mainmodule) < def.mclassdef.mclass then continue
-                               next_defs.add(def)
-                       end
-               end
-               var source = ""
-               if page.mbuilder.mpropdef2npropdef.has_key(self) then
-                       source = " {page.show_source(page.mbuilder.mpropdef2npropdef[self].location)}"
-               end
-               res.append("defined by {mclassdef.mmodule.html_full_namespace(page.mbuilder)}{source}")
+       private fun html_comment(page: NitdocPage) do
+               page.append("<div class='description'>")
                if not is_intro then
-                       source = ""
-                       if page.mbuilder.mpropdef2npropdef.has_key(mproperty.intro) then 
-                               source = " {page.show_source(page.mbuilder.mpropdef2npropdef[mproperty.intro].location)}"
-                       end
-                       res.append(", introduced by {mproperty.intro.mclassdef.mclass.link(page.mbuilder)}{source}")
-               end
-               if not previous_defs.is_empty then
-                       res.append(", inherited from ")
-                       for i in [0..previous_defs.length[ do
-                               var def = previous_defs[i]
-                               source = ""
-                               if page.mbuilder.mpropdef2npropdef.has_key(def) then 
-                                       source = " {page.show_source(page.mbuilder.mpropdef2npropdef[def].location)}"
+                       if page.ctx.mbuilder.mpropdef2npropdef.has_key(mproperty.intro) then
+                               var intro_nprop = page.ctx.mbuilder.mpropdef2npropdef[mproperty.intro]
+                               page.append("<textarea class='baseComment' data-comment-namespace='{mproperty.intro.mclassdef.mmodule.full_name}::{mproperty.intro.mclassdef.mclass.name}::{mproperty.name}' data-comment-location='{intro_nprop.doc_location.to_s}'>{intro_nprop.full_comment}</textarea>")
+                               if intro_nprop.full_comment.is_empty then
+                                       page.append("<p class='info inheritance'>")
+                                       page.append("<span class=\"noComment\">no comment for </span>")
+                               else
+                                       page.append("<div class='comment'>{intro_nprop.full_markdown}</div>")
+                                       page.append("<p class='info inheritance'>")
                                end
-                               res.append("{def.mclassdef.mclass.link(page.mbuilder)}{source}")
-                               if i < previous_defs.length - 1 then res.append(", ")
+                               page.append("introduction in ")
+                               mproperty.intro.mclassdef.html_namespace(page)
+                               page.append(" {page.show_source(intro_nprop.location)}</p>")
                        end
                end
-               if not next_defs.is_empty then
-                       res.append(", redefined by ")
-                       for i in [0..next_defs.length[ do
-                               var def = next_defs[i]
-                               source = ""
-                               if page.mbuilder.mpropdef2npropdef.has_key(def) then 
-                                       source = " {page.show_source(page.mbuilder.mpropdef2npropdef[def].location)}"
-                               end
-                                res.append("{def.mclassdef.mclass.link(page.mbuilder)}{source}")
-                                if i < next_defs.length - 1 then res.append(", ")
+               if page.ctx.mbuilder.mpropdef2npropdef.has_key(self) then
+                       var nprop = page.ctx.mbuilder.mpropdef2npropdef[self]
+                       page.append("<textarea class='baseComment' data-comment-namespace='{mclassdef.mmodule.full_name}::{mclassdef.mclass.name}::{mproperty.name}' data-comment-location='{nprop.doc_location.to_s}'>{nprop.full_comment}</textarea>")
+                       if nprop.full_comment == "" then
+                               page.append("<p class='info inheritance'>")
+                               page.append("<span class=\"noComment\">no comment for </span>")
+                       else
+                               page.append("<div class='comment'>{nprop.full_markdown}</div>")
+                               page.append("<p class='info inheritance'>")
+                       end
+                       if is_intro then
+                               page.append("introduction in ")
+                       else
+                               page.append("redefinition in ")
                        end
+                       mclassdef.html_namespace(page)
+                       page.append(" {page.show_source(nprop.location)}</p>")
                end
-               res.append(".</p>")
-               return res.to_s
+               page.append("</div>")
        end
 end
 
 redef class MMethodDef
-       redef fun html_full_desc(page) do
-               if not page.mbuilder.mpropdef2npropdef.has_key(self) then
-                       return ""
-               end
-               var res = new Buffer
-               var mprop = mproperty
-               var nprop = page.mbuilder.mpropdef2npropdef[self]
+       redef fun html_full_desc(page, ctx) do
                var classes = new Array[String]
-               var is_redef = mprop.intro_mclassdef.mclass != page.mclass
-               classes.add("fun")
-               if mprop.is_init then classes.add("init")
+               var is_redef = mproperty.intro_mclassdef.mclass != ctx
+               if mproperty.is_init then
+                       classes.add("init")
+               else
+                       classes.add("fun")
+               end
                if is_redef then classes.add("redef")
                classes.add(mproperty.visibility.to_s)
-               res.append("<article class='{classes.join(" ")}' id='{anchor}'>")
-               if nprop isa AAttrPropdef then
-                       if nprop.mreadpropdef == self then
-                               res.append("<h3 class='signature'>{mprop.name}: {nprop.html_signature(page.mbuilder)}</h3>")
-                       else
-                               res.append("<h3 class='signature'>{mprop.name}(value: {nprop.html_signature(page.mbuilder)})</h3>")
-                       end
+               page.append("<article class='{classes.join(" ")}' id='{anchor}'>")
+               if page.ctx.mbuilder.mpropdef2npropdef.has_key(self) then
+                       page.append("<h3 class='signature' data-untyped-signature='{mproperty.name}{msignature.untyped_signature(page)}'>")
+                       page.append("<span>{mproperty.html_name}")
+                       msignature.html_signature(page)
+                       page.append("</span></h3>")
                else
-                       var intro_nprop = page.mbuilder.mpropdef2npropdef[mprop.intro]
-                       res.append("<h3 class='signature'>{mprop.name}{intro_nprop.html_signature(page.mbuilder)}</h3>")
-               end
-               res.append(html_info(page))
-               res.append("<div class='description'>")
-               if nprop.comment == "" then
-                       res.append("<a class=\"newComment\" title=\"32\" tag=\"\">New Comment</a>")
+                       page.append("<h3 class='signature' data-untyped-signature='init{msignature.untyped_signature(page)}'>")
+                       page.append("<span>init")
+                       msignature.html_signature(page)
+                       page.append("</span></h3>")
+               end
+               html_info(page, ctx)
+               html_comment(page)
+               page.append("</article>")
+       end
+
+       redef fun html_info(page, ctx) do
+               page.append("<div class='info'>")
+               if mproperty.visibility < public_visibility then page.append("{mproperty.visibility.to_s} ")
+               if mproperty.intro_mclassdef.mclass != ctx then page.append("redef ")
+               if mproperty.is_init then
+                       page.append("init ")
                else
-                       res.append("<pre class=\"text_label\" title=\"\" name=\"\" tag=\"\" type=\"1\">{nprop.comment}</pre>")
+                       page.append("fun ")
                end
-               res.append("<textarea id=\"fileContent\" class=\"edit\" cols=\"76\" rows=\"1\" style=\"display: none;\"></textarea><a id=\"cancelBtn\" style=\"display: none;\">Cancel</a><a id=\"commitBtn\" style=\"display: none;\">Commit</a><pre id=\"preSave\" class=\"text_label\" type=\"2\"></pre>")
-               res.append(html_inheritance(page))
-               res.append("</div>")
-               res.append("</article>")
-               return res.to_s
-       end
-
-       redef fun html_info(page) do
-               var res = new Buffer
-               res.append("<div class='info'>")
-               if mproperty.visibility < public_visibility then res.append("{mproperty.visibility.to_s} ")
-               if mproperty.intro_mclassdef.mclass != page.mclass then res.append("redef ")
-               res.append("fun {mproperty.html_namespace(page.mbuilder)}")
-               res.append("</div>")
-               res.append("<div style=\"float: right;\"><a id=\"lblDiffCommit\"></a></div>")
-               return res.to_s
+               mproperty.html_namespace(page)
+               page.append("</div>")
        end
 end
 
 redef class MVirtualTypeDef
-       redef fun html_full_desc(page) do
-               var res = new Buffer
-               var mprop = mproperty
-               var is_redef = mprop.intro_mclassdef.mclass != page.mclass
+       redef fun html_full_desc(page, ctx) do
+               var is_redef = mproperty.intro_mclassdef.mclass != ctx
                var classes = new Array[String]
                classes.add("type")
                if is_redef then classes.add("redef")
                classes.add(mproperty.visibility.to_s)
-               res.append("<article class='{classes.join(" ")}' id='{anchor}'>")
-               res.append("<h3 class='signature'>{mprop.name}: {bound.link(page.mbuilder)}</h3>")
-               res.append(html_info(page))
-               res.append("<div class='description'>")
-
-               if page.mbuilder.mpropdef2npropdef.has_key(self) and page.mbuilder.mpropdef2npropdef[self].comment != "" then
-                       var nprop = page.mbuilder.mpropdef2npropdef[self]
-                       res.append("<pre class=\"text_label\" title=\"\" name=\"\" tag=\"\" type=\"1\">{nprop.comment}</pre>")
-               else
-                       res.append("<a class=\"newComment\" title=\"32\" tag=\"\">New Comment</a>")
+               page.append("<article class='{classes.join(" ")}' id='{anchor}'>")
+               page.append("<h3 class='signature' data-untyped-signature='{mproperty.name}'><span>{mproperty.html_name}: ")
+               bound.html_link(page)
+               page.append("</span></h3>")
+               html_info(page, ctx)
+               html_comment(page)
+               page.append("</article>")
+       end
+
+       redef fun html_info(page, ctx) do
+               page.append("<div class='info'>")
+               if mproperty.intro_mclassdef.mclass != ctx then page.append("redef ")
+               page.append("type ")
+               mproperty.html_namespace(page)
+               page.append("</div>")
+       end
+end
+
+redef class MSignature
+       private fun html_signature(page: NitdocPage) do
+               if not mparameters.is_empty then
+                       page.append("(")
+                       for i in [0..mparameters.length[ do
+                               mparameters[i].html_link(page)
+                               if i < mparameters.length - 1 then page.append(", ")
+                       end
+                       page.append(")")
+               end
+               if return_mtype != null then
+                       page.append(": ")
+                       return_mtype.html_link(page)
                end
-               res.append("<textarea id=\"fileContent\" class=\"edit\" cols=\"76\" rows=\"1\" style=\"display: none;\"></textarea><a id=\"cancelBtn\" style=\"display: none;\">Cancel</a><a id=\"commitBtn\" style=\"display: none;\">Commit</a><pre id=\"preSave\" class=\"text_label\" type=\"2\"></pre>")
-               res.append(html_inheritance(page))
-               res.append("</div>")
-               res.append("</article>")
-               return res.to_s
        end
 
-       redef fun html_info(page) do
+       private fun untyped_signature(page: NitdocPage): String do
                var res = new Buffer
-               res.append("<div class='info'>")
-               if mproperty.intro_mclassdef.mclass != page.mclass then res.append("redef ")
-               res.append("type {mproperty.html_namespace(page.mbuilder)}")
-               res.append("</div>")
-               res.append("<div style=\"float: right;\"><a id=\"lblDiffCommit\"></a></div>")
+               if not mparameters.is_empty then
+                       res.append("(")
+                       for i in [0..mparameters.length[ do
+                               res.append(mparameters[i].name)
+                               if i < mparameters.length - 1 then res.append(", ")
+                       end
+                       res.append(")")
+               end
                return res.to_s
        end
 end
 
+redef class MParameter
+       private fun html_link(page: NitdocPage) do
+               page.append("{name}: ")
+               mtype.html_link(page)
+               if is_vararg then page.append("...")
+       end
+end
+
 #
 # Nodes redefs
 #
 
-redef class AModule
-       private fun comment: String do
-               var ret = new Buffer
-               if n_moduledecl == null or n_moduledecl.n_doc == null then return ""
-               for t in n_moduledecl.n_doc.n_comment do
-                       ret.append(t.text.substring_from(1))
-               end
-               return ret.to_s.html_escape
+redef class ADoc
+       private fun short_comment: String do
+               return n_comment.first.text.substring_from(2).replace("\n", "").html_escape
        end
 
-       private fun short_comment: String do
-               var ret = new Buffer
-               if n_moduledecl != null and n_moduledecl.n_doc != null then
-                       ret.append(n_moduledecl.n_doc.n_comment.first.text.substring_from(2).replace("\n", ""))
+       private fun full_comment: String do
+               var res = new Buffer
+               for t in n_comment do
+                       var text = t.text
+                       text = text.substring_from(1)
+                       if text.first == ' ' then text = text.substring_from(1)
+                       res.append(text.html_escape)
                end
-               return ret.to_s.html_escape
+               var str = res.to_s
+               return str.substring(0, str.length - 1)
        end
 end
 
-redef class AStdClassdef
-       private fun comment: String do
-               var ret = new Buffer
-               if n_doc != null then
-                       for t in n_doc.n_comment do ret.append(t.text.substring_from(1))
+redef class AModule
+       private fun short_comment: String do
+               if n_moduledecl != null and n_moduledecl.n_doc != null then
+                       return n_moduledecl.n_doc.short_comment
                end
-               return ret.to_s.html_escape
+               return ""
        end
 
-       private fun short_comment: String do
-               var ret = new Buffer
-               if n_doc != null then ret.append(n_doc.n_comment.first.text.substring_from(2).replace("\n", ""))
-               return ret.to_s.html_escape
+       private fun full_comment: String do
+               if n_moduledecl != null and n_moduledecl.n_doc != null then
+                       return n_moduledecl.n_doc.full_comment
+               end
+               return ""
        end
-end
-
-redef class APropdef
-       private fun short_comment: String is abstract
-       private fun html_signature(mbuilder: ModelBuilder): String is abstract
-       private fun comment: String is abstract
-end
 
-redef class AAttrPropdef
-       redef fun short_comment do
-               var ret = new Buffer
-               if n_doc != null then ret.append(n_doc.n_comment.first.text.substring_from(2).replace("\n", ""))
-               return ret.to_s.html_escape
+       private fun full_markdown: String do
+               if n_moduledecl != null and n_moduledecl.n_doc != null then
+                       return n_moduledecl.n_doc.full_markdown.html
+               end
+               return ""
        end
 
-       redef private fun comment: String do
-               var ret = new Buffer
-               if n_doc != null then
-                       for t in n_doc.n_comment do ret.append(t.text.substring_from(1))
+       private fun doc_location: Location do
+               if n_moduledecl != null and n_moduledecl.n_doc != null then
+                       return n_moduledecl.n_doc.location
                end
-               return ret.to_s.html_escape
+               return location
        end
+end
 
-       redef fun html_signature(mbuilder) do
-               if n_type != null then return n_type.mtype.link(mbuilder)
+redef class AStdClassdef
+       private fun short_comment: String do
+               if n_doc != null then return n_doc.short_comment
                return ""
        end
-end
 
-redef class AMethPropdef
-       redef fun short_comment do
-               var ret = new Buffer
-               if n_doc != null then ret.append(n_doc.n_comment.first.text.substring_from(2).replace("\n", ""))
-               return ret.to_s.html_escape
+       private fun full_comment: String do
+               if n_doc != null then return n_doc.full_comment
+               return ""
        end
 
-       redef private fun comment: String do
-               var ret = new Buffer
-               if n_doc != null then
-                       for t in n_doc.n_comment do ret.append(t.text.substring_from(1))
-               end
-               return ret.to_s.html_escape
+       private fun full_markdown: String do
+               if n_doc != null then return n_doc.full_markdown.html
+               return ""
        end
 
-       redef fun html_signature(mbuilder) do
-               if n_signature != null then return n_signature.to_html(mbuilder)
-               return ""
+       private fun doc_location: Location do
+               if n_doc != null then return n_doc.location
+               return location
        end
 end
 
-redef class ATypePropdef
-       redef fun short_comment do
-               var ret = new Buffer
-               if n_doc != null then ret.append(n_doc.n_comment.first.text.substring_from(2).replace("\n", ""))
-               return ret.to_s.html_escape
+redef class APropdef
+       private fun short_comment: String do
+               if n_doc != null then return n_doc.short_comment
+               return ""
        end
 
-       redef private fun comment: String do
-               var ret = new Buffer
-               if n_doc != null then
-                       for t in n_doc.n_comment do ret.append(t.text.substring_from(1))
-               end
-               return ret.to_s.html_escape
+       private fun full_comment: String do
+               if n_doc != null then return n_doc.full_comment
+               return ""
        end
 
-       redef fun html_signature(mbuilder) do
-               return mpropdef.bound.link(mbuilder)
+       private fun full_markdown: String do
+               if n_doc != null then return n_doc.full_markdown.html
+               return ""
        end
-end
 
-redef class ASignature
-       fun to_html(mbuilder: ModelBuilder): String do
-               #TODO closures
-               var res = new Buffer
-               if not n_params.is_empty then
-                       res.append("(")
-                       for i in [0..n_params.length[ do
-                               res.append(n_params[i].to_html(mbuilder))
-                               if i < n_params.length - 1 then res.append(", ")
-                       end
-                       res.append(")")
-               end
-               if n_type != null and n_type.mtype.link(mbuilder) != "" then res.append(": {n_type.mtype.link(mbuilder)}")
-               return res.to_s
+       private fun doc_location: Location do
+               if n_doc != null then return n_doc.location
+               return location
        end
 end
 
-redef class AParam
-       fun to_html(mbuilder: ModelBuilder): String do
-               var ret = "{n_id.text}"
-               if n_type != null then
-                       ret = "{ret}: {n_type.mtype.link(mbuilder)}"
-                       if n_dotdotdot != null then ret = "{ret}..."
-               end
-               return ret
-       end
-end
 
 var nitdoc = new NitdocContext
 nitdoc.generate_nitdoc