Skip to content

HTML class attribute multi-value extraction collapses tokens #2103

Description

@Widthdom

Summary

HTML class attribute values contain space-separated class names that should each be indexed as distinct symbol references, not as a single blob. Currently, <div class="btn btn-primary mx-2"> captures the entire string as one symbol, preventing fine-grained class lookups (e.g., searching for "btn" or "mx-2"). This is especially critical for Tailwind CSS and other utility-first frameworks where individual class names are the navigation unit.

Where

  • src/CodeIndex/Indexer/Symbols/SymbolExtractor.Markup.cs:ExtractHtmlSymbols() — Attribute value processing loop (around line 180-230) enumerates attribute names and values but treats multi-valued strings as atomic
  • Tests: No coverage in tests/CodeIndex.Tests/SymbolExtractorTests.cs for class attribute enumeration

Suggested approach

  1. When processing class attribute (and similarly className in XHTML/JSX contexts), split the value on whitespace after extracting the quoted/unquoted value
  2. Emit one symbol record per whitespace-separated token
  3. Validate against edge cases: empty tokens (double spaces), special CSS characters (:, [, ]), and Tailwind variant syntax (e.g., md:flex, hover:bg-red)
  4. Consider normalizing leading/trailing whitespace and collapsing internal runs
  5. Add test coverage for minified HTML with multi-class attributes and Tailwind-like class names

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions