From 2a8c1166b168c2a04625cd991503bc2375d9a9f6 Mon Sep 17 00:00:00 2001 From: sdarbinyan Date: Fri, 17 Jul 2026 16:28:53 +0400 Subject: [PATCH] feat(project-editor): syntax-highlighted code editor for HTML raw mode - shared app-code-editor: overlay textarea + highlighted
 layer,
  no external dependency (Monaco/CodeMirror)
- tokenizeCss: selector/property/value/string/comment/at-rule aware,
  brace-depth state machine
- tokenizeHtml: tags + comments colored, delegates ` is delegated to the CSS tokenizer, since that is
+ * where marketplace static pages actually author CSS.
+ */
+export function tokenizeHtml(html: string): HighlightToken[] {
+  const tokens: HighlightToken[] = [];
+  let i = 0;
+
+  while (i < html.length) {
+    if (html.startsWith('', i + 4);
+      const stop = end === -1 ? html.length : end + 3;
+      tokens.push({ text: html.slice(i, stop), cls: 'cm-comment' });
+      i = stop;
+      continue;
+    }
+    if (html[i] === '<') {
+      let j = i + 1;
+      let inStr: string | null = null;
+      while (j < html.length) {
+        const ch = html[j];
+        if (inStr) {
+          if (ch === inStr) inStr = null;
+          j++;
+          continue;
+        }
+        if (ch === '"' || ch === "'") {
+          inStr = ch;
+          j++;
+          continue;
+        }
+        if (ch === '>') {
+          j++;
+          break;
+        }
+        j++;
+      }
+      const tagText = html.slice(i, j);
+      tokens.push(...tokenizeTag(tagText));
+      const isStyleOpenTag = /^]*)?>$/i.test(tagText);
+      i = j;
+      if (isStyleOpenTag) {
+        const closeIdx = html.toLowerCase().indexOf(' (token.cls ? `${escapeHtml(token.text)}` : escapeHtml(token.text))).join('');
+}