Fix syntax worker based highlighting

HighlightJS produces HTML highlighting in the form of
`<span class="something">text</span>`. But if such an HTML string is
the *input* for syntax highlighting, then our parser would choke on
translating the highlighted HTML back to ranges. Because at the end
it would also interpret the actual code as being a syntax highlighting
marker.

The fix is to keep track of where we are within a line of highlighted
code instead of trying to always match from the beginning of the line.

Google-Bug-Id: b/222020522
Release-Notes: skip
Change-Id: Ie977bd0964df42b7bb7bff870bb064ee45c4f4be
diff --git a/polygerrit-ui/app/utils/syntax-util_test.ts b/polygerrit-ui/app/utils/syntax-util_test.ts
index fef908a..226f962 100644
--- a/polygerrit-ui/app/utils/syntax-util_test.ts
+++ b/polygerrit-ui/app/utils/syntax-util_test.ts
@@ -99,6 +99,27 @@
       );
     });
 
+    test('one complex line with escaped HTML', async () => {
+      assert.deepEqual(
+        highlightedStringToRanges(
+          '  <span class="tag">&lt;<span class="name">span</span> <span class="attr">class</span>=<span class="string">&quot;title&quot;</span>&gt;</span>[[name]]<span class="tag">&lt;/<span class="name">span</span>&gt;</span>'
+        ),
+        [
+          {
+            ranges: [
+              // '  <span class="title">[[name]]</span>'
+              {start: 2, length: 20, className: 'tag'},
+              {start: 3, length: 4, className: 'name'},
+              {start: 8, length: 5, className: 'attr'},
+              {start: 14, length: 7, className: 'string'},
+              {start: 30, length: 7, className: 'tag'},
+              {start: 32, length: 4, className: 'name'},
+            ],
+          },
+        ]
+      );
+    });
+
     test('two lines, one span each', async () => {
       assert.deepEqual(
         highlightedStringToRanges(