Skip to content
New issue

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

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

Already on GitHub? # to your account

Support for Classes on All Tag Types #984

Open
aretrosen opened this issue Nov 14, 2024 · 1 comment
Open

Support for Classes on All Tag Types #984

aretrosen opened this issue Nov 14, 2024 · 1 comment

Comments

@aretrosen
Copy link

Can we add classes to tags other than Heading? I couldn't find a solution for this. It might be useful to do so in cases like adding dir=auto to the classes of Tag::Paragraph or Tag::List. I might be missing a better approach.

Currently, I am achieving this for Tag::Heading using the following code:

let parser = Parser::new_ext(markdown_input, options).map(|event| match event {
    Event::Start(mut tag) => {
        if let Tag::Heading { classes, .. } = &mut tag {
            classes.push("dir=auto".into());
        }
        Event::Start(tag)
    }
    _ => event,
});

Can we do this in other ways that I might not be aware of, which might be applicable to Tag::Paragraph and others too?

@systemsoverload
Copy link

I think their implementation goes a bit too far, but something like this would be ideal for all some elements. My use case (currently achieved by a pretty nasty custom iterator) is for adding data attributes like [foo](https://my-link){: data-baz='bar' }

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants