Skip to content

Convert from Tag to TagEnd #696

@rambip

Description

@rambip

I use a fork following the unreleased version of the main branch (https://github.com/rhysd/pulldown-cmark/tree/math)

In my project, I'm creating my own rendering pipeline from the events Parse created.
To get the children attributes when I match an opening tag, I would like to do something like this:

fn render_tag<'a>(context: &RenderContext, stream: &mut EventStream<'a>, tag: Tag<'a>) -> Result<Html, HtmlError> {
    let children = 
        stream
        .take_while(|(event, range)| event != Event::Start(corresponding_closing_tag(tag))
        .collect();

    match tag {
        Tag::Paragraph => todo!(),
        Tag::Heading(_, _, _) => todo!(),
        Tag::BlockQuote => todo!(),
        Tag::CodeBlock(_) => todo!(),
        Tag::List(_) => todo!(),
        Tag::Item => todo!(),
        Tag::FootnoteDefinition(_) => todo!(),
        Tag::Table(_) => todo!(),
        Tag::TableHead => todo!(),
        Tag::TableRow => todo!(),
        Tag::TableCell => todo!(),
        Tag::Emphasis => todo!(),
        Tag::Strong => todo!(),
        Tag::Strikethrough => todo!(),
        Tag::Link(_, _, _) => todo!(),
        Tag::Image(_, _, _) => todo!(),
    }
}

But it seems there is no way to turn an opening tag into a closing tag, or at leat test if a Tag and a TagEnd match.
Am I missing something ?

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