Add name_source_location() and value_source_location() to Attribute#313
Conversation
eff9dd6 to
e605251
Compare
|
Thanks for the PR. The change isn't too bad, but it makes me wonder why aren't you using the rewriter to do rewriting? |
Exposes document-absolute byte ranges for attribute names and values via the existing SourceLocation type. Returns None for attributes added programmatically via set_attribute. This enables downstream consumers to perform byte-level splice rewrites on attribute values without re-parsing the start tag.
e605251 to
b33681f
Compare
Yes this is a very good question and I should've led with that. The reason is: we rewrite html bodies not written by us. We used to do this with regexps and it was very imprecise and so often we targeted nodes that were unrelated to the reason for the rewrite. For example, if your body contained Changing the payload we output is like turning a cargo ship around, and while we want to move to full It's not great and I know it's not how you want us to use it, but it's also 2-7x faster and approximately infinity times more precise. |
|
@kornelski would you cut a new release please? 🙏 |
Exposes document-absolute byte ranges for attribute names and values via the existing SourceLocation type.
We need this to perform byte-level splice rewrites on attribute values without re-parsing the start tag... I know we're holding it wrong but this is the fastest and most correct way to achieve our goals :)