Fix syntax highlighting of multi-line comments

When syntax highlighting a multi-line comment block, e.g.:

  /* This is a function that
   * does some work.
   */

we must pass the /* to the prettify library on each of the three
lines in the block, otherwise the remaining lines think they are
outside of a comment and process as source code, rather than as a
comment style.

This requires us to now keep track of state between lines, so we
can tell whether or not we need to inject the /* at the start of a
line before feeding it to the prettify library.  Unfortunately this
means Gerrit code now has to understand at least some basics of
the language, reducing the value of reusing the prettify library.

My initial attempt to fix this bug was to expand out both sides
of the file and format them as-is (as a single huge string), then
split that formatted result apart and display the relevant lines.
This turned out to run very slowly, especially when the user turns on
"Show full files" as we were prettifying two complete copies of the
file (old version and new version).  To make matters more difficult,
the prettify routine creates HTML spans that span multiple lines,
which then makes it impossible to just split on line breaks and
display only the relevant sections again.

Bug: GERRIT-250
Signed-off-by: Shawn O. Pearce <sop@google.com>
7 files changed