#2418 Disable line number IDs in syntax::HtmlSyntaxWriter

SlimerDude Sat 16 May 2015

I was just thinking it'd be useful if syntax::HtmlSyntaxWriter had an option to disable the line number ID generation. That way you could embed several generated HTML sections in the one document.

I know it's trivial to write your own HtmlSyntaxWriter class / writeLine() method (*), but it's always nice not to duplicate code and effort.

(*) well, it would be if syntax::SyntaxType.html was public.

My current workaround:

Void writeLines(WebOutStream out, SyntaxDoc doc, Bool renderLineIds) {
    out.pre
    doc.eachLine |line| { 
        if (renderLineIds) out.span("id=\"line${line.num}\"")
        line.eachSegment |type, text| {
            html := (Str?) SyntaxType#.field("html").get(type)
            if (html != null)
                out.writeChar('<').print(html).writeChar('>')
            out.writeXml(text)
            if (html != null)
                out.writeChars("</").print(html).writeChar('>')
        }
        if (renderLineIds) out.spanEnd
        out.writeChar('\n')     
    }
    out.preEnd
}

Login or Signup to reply.