lib/github: handles commit comments
[nit.git] / src / highlight.nit
index 1165ac9..d70281e 100644 (file)
@@ -29,6 +29,14 @@ class HighlightVisitor
        # Used to have a really huge and verbose HTML (mainly for debug)
        var with_ast = false is writable
 
+       # Prefixes used in generated IDs for line `<span>` elements.
+       # Useful if more than one highlighted code is present in the same HTML document.
+       #
+       # If set to the empty string, id for lines are disabled.
+       #
+       # Is `"L"` by default.
+       var line_id_prefix = "L" is writable
+
        # The first line to generate, null if start at the first line
        var first_line: nullable Int = null is writable
 
@@ -82,7 +90,8 @@ class HighlightVisitor
 
                                # Add a div for the whole line
                                var tag = new HTMLTag("span")
-                               tag.attrs["id"] = "L{cline}"
+                               var p = line_id_prefix
+                               if p != "" then tag.attrs["id"] = "{p}{cline}"
                                tag.classes.add "line"
                                stack2.add(html)
                                html.add tag
@@ -349,6 +358,8 @@ redef class MClassDef
                if mdoc == null then mdoc = mclass.intro.mdoc
                if mdoc != null then mdoc.fill_infobox(res)
 
+               if in_hierarchy == null then return res
+
                if in_hierarchy.greaters.length > 1 then
                        var c = res.new_dropdown("hier", "super-classes")
                        for x in in_hierarchy.greaters do
@@ -395,11 +406,11 @@ redef class MPropDef
                var res = new HInfoBox(v, to_s)
                res.href = href
                if self isa MMethodDef then
-                       res.new_field("fun").append(mproperty.name).add msignature.linkto
+                       if msignature != null then res.new_field("fun").append(mproperty.name).add msignature.linkto
                else if self isa MAttributeDef then
-                       res.new_field("fun").append(mproperty.name).add static_mtype.linkto
+                       if static_mtype != null then res.new_field("fun").append(mproperty.name).add static_mtype.linkto
                else if self isa MVirtualTypeDef then
-                       res.new_field("add").append(mproperty.name).add bound.linkto
+                       if bound != null then res.new_field("add").append(mproperty.name).add bound.linkto
                else
                        res.new_field("wat?").append(mproperty.name)
                end