INNER CODE UNIT · JavaScript

comments

nadimtuhin/claude-token-optimizer · src/commands/compress.js:43

  const comments = result.match(/<!--[\s\S]*?-->/g) ?? [];
  if (comments.length > 0) {
    result = result.replace(/<!--[\s\S]*?-->/g, '');
    changes.push(`Removed ${comments.length} HTML comment${comments.length > 1 ? 's' : ''}`);
  }

  // ponytail: lazy match stops at the first </svg>, so nested <svg> blocks leave
  // residue behind. Ceiling: nested SVGs aren't fully collapsed. Upgrade path: a
  // balance-count scan tracking open/close <svg> tag depth.
  // Opening tag must not end with "/>" — a self-closing <svg/> is not a block start.
  const svgs = result.match(/<svg\b(?:[^>]*[^/>])?>[\s\S]*?<\/svg>/gi) ?? [];
  if (svgs.length > 0) {
    result = result.replace(/<svg\b(?:[^>]*[^/>])?>[\s\S]*?<\/svg>/gi, '[SVG Asset]');
    changes.push(`Collapsed ${svgs.length} inline SVG${svgs.length > 1 ? 's' : ''} to [SVG Asset]`);
  }

  return { result, changes };
}

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…