On Thu, Jun 28, 2018 at 10:40:19AM -0500, Lester L. Martin II wrote: > > I've developed a way to do highlighting with line numbering... > The issues are as follows however: > 1. The JS code responsible for the highlighting is external to Fossil > itself. > 2. The JS code highlights <pre><code> blocks, so if there is a > `<pre><code>$line</code><code>$line2</code></pre>` each code block is > highlighted individually. > 3. Context is lost between code blocks. > > Each line gets wrapped in a separate code block because you can use > css to insert a line number vs manually inserting the line number via > code per line. > > That said, if you have a comment block `/* comments */` broken up over > a few lines, it won't apply the comment coloring to the lines > in-between when line numbering is enabled. Thus, I'd consider that > while it half works, such is inherently broken unless we decide to > depend upon a certain JS library to handle highlighting.
I think a cleaner approach, though it might take a bit of rewriting for file display, would use an HTML table, possibly assembled by JavaScript. Note that I'm feeling a little dirty for suggesting this; it's something that could also reasonably be done server-side, though it would probably require using something server-side for the syntax highlighting, too. See if this makes sense: Apply syntax highlighting to a block of code. Organize the code in second column TD elements of a table. Organize line numbers in first column TD elements of a table. Thus, you would have HTML for a line of code that looks something like this (using a totally made-up function as example code): <tr> <td class="line-no">$num</td> <td class="code-line"> <span class="color-type">uint16_t</span> <span class="color-label">get_next</span><span class="color-delim">() {</span> </td> </tr> Of course, that's just off the top of my head. I don't actually know how the HTML resulting from application of the syntax highlighting code would look in this case. The upshot, though, is that applying syntax highlighting to the code to be displayed first, then organizing it into table cells with number cells, might avoid JS syntax highlighting issues with line numbers, including any issues around multiline highlighting. The downside is that it would result in either having to do all line numbering in JS or applying syntax highlighting server-side. -- Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ] _______________________________________________ fossil-users mailing list fossil-users@lists.fossil-scm.org http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users