You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In rust-lang/rust#77119, rustdoc wants to warn about unclosed HTML tags in docs:
/// <script>//~^ ERROR Unclosed HTML tag `script`
@GuillaumeGomez started working on a bespoke HTML parser, which is clearly not ideal. Is it possible to have pulldown add more info about the HTML tags it parses? Right now it just has a Cow which doesn't tell you the name of the tag.
More concretely, we'd like to know
When a tag starts
When it ends
The name of the tag
We don't need any sort of HTML validation, although if you want to add this lint to pulldown itself I'd have no objection ;)
Just a question to clarify so we don't mean different things: by the 'end' of a tag, do you mean where its associated closing tag is? Because where a tag itself starts and ends in the source, i.e. its span, should already be presented when using the offset iterator.
If that is indeed what you mean, then I believe it may be out of scope for pulldown. We do very minimal HTML parsing, just enough to ensure that what we're emitting as HTML tags are in fact valid HTML tags. You can rely on pulldown to do this. If we fail to recognize valid tags or incorrectly emit tags which aren't HTML, then that is a bug.
We do however not check valid HTML itself, however. We do not match opening and closing tags, nor do we verify that the tags form a valid tree. Pulldown will happily emit <div><p>test</div></p> as a sequence of HTML. That would be HTML validation, and I think it's orthogonal to parsing markdown. As a rule of thumb, I think we should only do in pulldown what cannot be built on top of pulldown equally as efficiently. This is both to ensure that we don't do unnecessary work that may not be of interest to all users, and to keep a clean separation of responsibility.
I do believe that getting tag names should be fairly straightforward by scanning alphabetical characters after html span start (with an offset of 1 to skip the opening <). Matching opening and closing tags, and validating HTML will obviously require more effort, but this will be no harder than doing it inside of pulldown. There may be existing HTML parsers to help you out as well.
by the 'end' of a tag, do you mean where its associated closing tag is?
Yes, that's what I mean.
As a rule of thumb, I think we should only do in pulldown what cannot be built on top of pulldown equally as efficiently. This is both to ensure that we don't do unnecessary work that may not be of interest to all users, and to keep a clean separation of responsibility.
Ok, that makes sense. I'll look into some HTML parsing libraries :)
@jyn514 I feel like pulling in a second parsing library into rustdoc may also be too much. I think the approach there is to do extremely limited parsing of tags as I mentioned in a comment there.
Activity
marcusklaas commentedon Sep 25, 2020
Just a question to clarify so we don't mean different things: by the 'end' of a tag, do you mean where its associated closing tag is? Because where a tag itself starts and ends in the source, i.e. its span, should already be presented when using the offset iterator.
If that is indeed what you mean, then I believe it may be out of scope for pulldown. We do very minimal HTML parsing, just enough to ensure that what we're emitting as HTML tags are in fact valid HTML tags. You can rely on pulldown to do this. If we fail to recognize valid tags or incorrectly emit tags which aren't HTML, then that is a bug.
We do however not check valid HTML itself, however. We do not match opening and closing tags, nor do we verify that the tags form a valid tree. Pulldown will happily emit
<div><p>test</div></p>as a sequence of HTML. That would be HTML validation, and I think it's orthogonal to parsing markdown. As a rule of thumb, I think we should only do in pulldown what cannot be built on top of pulldown equally as efficiently. This is both to ensure that we don't do unnecessary work that may not be of interest to all users, and to keep a clean separation of responsibility.I do believe that getting tag names should be fairly straightforward by scanning alphabetical characters after html span start (with an offset of 1 to skip the opening
<). Matching opening and closing tags, and validating HTML will obviously require more effort, but this will be no harder than doing it inside of pulldown. There may be existing HTML parsers to help you out as well.jyn514 commentedon Sep 25, 2020
Yes, that's what I mean.
Ok, that makes sense. I'll look into some HTML parsing libraries :)
Manishearth commentedon Sep 25, 2020
@jyn514 I feel like pulling in a second parsing library into rustdoc may also be too much. I think the approach there is to do extremely limited parsing of tags as I mentioned in a comment there.