Skip to content

Provide source spans for tokens and DOM nodes #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
kmcallister opened this issue Oct 21, 2014 · 4 comments
Open

Provide source spans for tokens and DOM nodes #48

kmcallister opened this issue Oct 21, 2014 · 4 comments

Comments

@kmcallister
Copy link
Contributor

We can use something like libsyntax's Span and Spanned types to track positions in the input stream.

The tokenizer will remember its current position and the position at certain events, e.g. start tag, start attribute name. The tree builder will call a tree sink method (with an empty default) to annotate the DOM with span information.

Then we can write a command-line HTML validator with the same output UI as rustc :)

Note that eventually it will be possible for a single document's nodes to come from multiple text sources, e.g. with document.write.

@707090
Copy link

707090 commented Aug 17, 2020

I am interested in this feature. What is the status of this? Is there some spanning information available or is this yet to be implemented?

My use case is that I am using html5ever in my proc macros to parse templates for a web framework and I would like to give errors with spans that point various parts of the original HTML

@jdm
Copy link
Member

jdm commented Aug 17, 2020

The tree builder sink is notified when the current line is updated via

self.sink.set_current_line(line_number);
.

@noahbald
Copy link

noahbald commented May 7, 2024

Are there any plans to add this to rcdom/markup5ever?

@jbirnick
Copy link

I would also love to have support for Spans!

(The use case is editing certain parts of HTML documents, but most of the document should just stay exactly as it is. [Not parse and serialize again, just leave it untouched.] Then I could parse it with html5ever and just edit the relevant parts of file.)

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

No branches or pull requests

5 participants