feat(element): Expose attribute source locations - #143
Merged
Conversation
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.
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
element.attribute_source_location(name)which returnsthe byte ranges of an attribute's name and value in the
original input as
{ name: Range, value: Range | nil }.nilwhen the attribute is missing, was added ormodified during the rewrite, or is a bare boolean attribute
(e.g.
<input disabled>) — lol_html does not record aposition in those cases.
back to exact source bytes for precise diagnostics or
surgical edits outside the rewriter.
underlying
name_source_location/value_source_locationAPIs this feature depends on.
Test plan
bundle exec rake compilebundle exec rake test TEST=test/selma_rewriter_attribute_source_location_test.rbbundle exec rake test