highlight: add HighlightVisitor::line_id_prefix to control ids of line spans
authorJean Privat <jean@pryen.org>
Tue, 16 Dec 2014 13:57:05 +0000 (08:57 -0500)
committerJean Privat <jean@pryen.org>
Wed, 17 Dec 2014 04:43:29 +0000 (23:43 -0500)
Signed-off-by: Jean Privat <jean@pryen.org>

src/highlight.nit

index 5e3acf1..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