feat(html): HTML accessibility-tree backend - #43
Merged
Conversation
Teaches git-ast to treat HTML files semantically. The DOM is projected as an accessibility tree (landmarks, headings, interactive elements) so `git-ast inspect`, `match`, and `blame` track DOM identity across commits the same way they track Rust function identity. Key design decisions: - `canonicalize()` normalises attribute ordering + quoting and lowercases tag names but keeps the output as valid HTML (not JSON), so working trees stay readable and round-trip losslessly. - `inspect()` returns `Vec<Def>` for semantically meaningful elements only (landmarks, headings, img, button, input, …). Presentational divs/spans with no role are ignored. - `content_hash`: FNV-1a over `role\0name\0tag\0sorted-attrs`. - `shape_hash`: same preimage with the accessible name AND its contributing attrs (aria-label, title, alt) replaced by `_` so a relabelled nav shares its shape with the original. - `subtree_hashes`: one hash per semantic unit, enabling the existing Dice-similarity fuzzy matching from `identity::match_defs`. - Extension dispatch wired into filters (clean/smudge), `inspect`, and `match`; `setup` registers *.html / *.htm gitattributes entries. - Depends on tree-sitter-html 0.20 (matching tree-sitter-rust 0.21's API style); in 0.20, void elements are `element → self_closing_tag` (not `self_closing_element`), handled defensively in `element_to_def`. 97/97 tests green (20 new HTML tests). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
src/html.rs— a new language backend that projects HTML DOM into an accessibility tree (Vec<Def>) for semantic identity trackinggit-ast inspect,git-ast match, andgit-ast setup(registers*.html/*.htmgitattributes)tree-sitter-html = "0.23"to"0.20"to match the API style oftree-sitter-rust = "0.21"(both use alanguage()fn rather than the 0.23LANGUAGEconst)How it works:
canonicalize()— normalises attribute ordering (alphabetical), double-quotes all values, lowercases tag names; output is valid HTML (not JSON) so working trees stay readableinspect()— returns aDeffor each semantically meaningful element (landmarks, headings, interactive, img). Non-semantic divs/spans are skippedcontent_hash— FNV-1a overrole\0name\0tag\0sorted-k=v(role + accessible name + structure)shape_hash— same preimage with accessible name AND its source attrs (aria-label,title,alt) replaced by_, so two navs that differ only in label share a shape hash and fuzzy-match correctlysubtree_hashes— one hash per semantic unit, feeding directly into the existingidentity::match_defsDice-similarity matchingKey implementation note: tree-sitter-html 0.20 represents void elements (
<img />) aselement → self_closing_tag(notself_closing_element), soelement_to_defhandles bothstart_tagandself_closing_tagchildren defensively.Test plan
html::testscovering: canonicalization, attribute sorting, idempotency, DOCTYPE normalization, accessible name resolution (aria-label / alt / text / title priority), role mapping, implicit/explicit roles,inspectelement discovery, content_hash stability, shape_hash rename detection, subtree_hashes presencecargo test --lib)cargo test)cargo buildcompiles clean (zero warnings)PR checklist
printer.rs(private there); a follow-up can extract it if the pattern repeats againsrc/html.rs🤖 Generated with Claude Code