Skip to content

feat(element): Expose attribute source locations - #143

Merged
gjtorikian merged 2 commits into
mainfrom
expose-attribute-source-locations
Jun 3, 2026
Merged

feat(element): Expose attribute source locations#143
gjtorikian merged 2 commits into
mainfrom
expose-attribute-source-locations

Conversation

@gjtorikian

Copy link
Copy Markdown
Owner

Summary

  • Add element.attribute_source_location(name) which returns
    the byte ranges of an attribute's name and value in the
    original input as { name: Range, value: Range | nil }.
  • Returns nil when the attribute is missing, was added or
    modified during the rewrite, or is a bare boolean attribute
    (e.g. <input disabled>) — lol_html does not record a
    position in those cases.
  • Motivated by consumers that need to map rewriter callbacks
    back to exact source bytes for precise diagnostics or
    surgical edits outside the rewriter.
  • Picks up the lol_html 2.9.0 bump, which exposes the
    underlying name_source_location / value_source_location
    APIs this feature depends on.

Test plan

  • bundle exec rake compile
  • bundle exec rake test TEST=test/selma_rewriter_attribute_source_location_test.rb
  • Full suite: bundle exec rake test
  • Spot-check README snippet renders correctly on GitHub

Consumers that rewrite HTML need to map back to the exact bytes
an attribute occupied in the original input — for example, to
produce precise diagnostics or surgical edits outside the
rewriter. lol_html records this position info on attributes but
Selma did not surface it.

Returns nil for attributes that were added or modified during
the rewrite and for bare boolean attributes (e.g. `<input
disabled>`), since lol_html does not track a location for those.
@gjtorikian
gjtorikian merged commit e21d189 into main Jun 3, 2026
6 of 9 checks passed
@gjtorikian
gjtorikian deleted the expose-attribute-source-locations branch June 3, 2026 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant