Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Parse HTML tags, not just markdown tags #484

Closed

Description

@jyn514

Let me know if this request is over the top :)

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 ;)

cc @Manishearth

Activity

  1. marcusklaas commented on Sep 25, 2020

    @marcusklaas
    Collaborator

    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.

  2. jyn514 commented on Sep 25, 2020

    @jyn514
    ContributorAuthor

    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 :)

  3. Manishearth commented on Sep 25, 2020

    @Manishearth
    Contributor

    @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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions