Skip to content
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

pandoc alerts extension #117

Open
bucweat opened this issue Sep 29, 2024 · 3 comments
Open

pandoc alerts extension #117

bucweat opened this issue Sep 29, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@bucweat
Copy link

bucweat commented Sep 29, 2024

Hi,

Trying to use Pandoc alerts extension for CommonMark (see second bullet):

https://pandoc.org/releases.html#pandoc-3.1.10-2023-12-12

My markdown file has

> [!NOTE]  
> Highlights information that users should take into account, even when skimming.

If I use https://github.com/lambdalisue/rs-mdbook-alerts it renders in html as expected. I would like to get something similar in pandoc pdf.

In my book.toml I put

from = "commonmark+alerts"

But my resulting pdf has what looks like the raw markdown without the >. I know from pandoc issue not to expect svg icon, but I would have expected NOTE without the ![].

image

I'm using pandoc 3.4.

Am I using the from= with the alerts extension correctly?

@max-heller
Copy link
Owner

max-heller commented Oct 4, 2024

You're using it correctly, I believe the issue lies with pulldown_cmark_to_cmark (which is used to convert parsed Markdown back into raw Markdown text).

When I run this test:

#[test]
fn alerts_pulldown_cmark_to_cmark() {
    let source = "
> [!NOTE]  
> Highlights information that users should take into account, even when skimming.
    ";
    let events = pulldown_cmark::Parser::new(source).into_offset_iter();
    let mut roundtripped = String::new();
    pulldown_cmark_to_cmark::cmark_with_source_range(
        events.map(|(event, range)| (event, Some(range))),
        source,
        &mut roundtripped,
    )
    .unwrap();
    assert_eq!(source, roundtripped);
}

I see that the resulting Markdown has an extra line of the blockquote at the beginning:

>
> [!NOTE]  
> Highlights information that users should take into account, even when skimming.

This makes Pandoc very unhappy and it no longer considers it an alert:

  • Before:

    $ echo '> [!NOTE]\n> Highlights information that users should take into account, even when skimming.' | pandoc -f commonmark+alerts -t native
    [ Div
        ( "" , [ "note" ] , [] )
        [ Div ( "" , [ "title" ] , [] ) [ Para [ Str "Note" ] ]
        , Para
            [ Str "Highlights"
            , Space
            , Str "information"
            , Space
            , Str "that"
            , Space
            , Str "users"
            , Space
            , Str "should"
            , Space
            , Str "take"
            , Space
            , Str "into"
            , Space
            , Str "account,"
            , Space
            , Str "even"
            , Space
            , Str "when"
            , Space
            , Str "skimming."
            ]
        ]
    ]
  • After:

    $ echo '>\n> [!NOTE]\n> Highlights information that users should take into account, even when skimming.' | pandoc -f commonmark+alerts -t native
    [ BlockQuote
        [ Para
            [ Str "[!NOTE]"
            , SoftBreak
            , Str "Highlights"
            , Space
            , Str "information"
            , Space
            , Str "that"
            , Space
            , Str "users"
            , Space
            , Str "should"
            , Space
            , Str "take"
            , Space
            , Str "into"
            , Space
            , Str "account,"
            , Space
            , Str "even"
            , Space
            , Str "when"
            , Space
            , Str "skimming."
            ]
        ]
    ]

I'll take a look into pulldown_cmark_to_cmark and see if there's an easy way to fix this.

  • This still happens on the latest version:
    Compiling pulldown-cmark v0.12.1
    Compiling pulldown-cmark-to-cmark v17.0.0
    

@max-heller
Copy link
Owner

max-heller commented Oct 5, 2024

Unfortunately I think this'll be blocked for a while.

Newer (breaking) versions of pulldown_cmark support alerts, but I'm holding off from updating until mdbook does so (which requires a breaking change) to make sure parsing is consistent (#115).

Additionally, even the latest pulldown_cmark_to_cmark needs a fix: Byron/pulldown-cmark-to-cmark#86

@max-heller max-heller added the bug Something isn't working label Oct 5, 2024
@bucweat
Copy link
Author

bucweat commented Oct 5, 2024

Thank you for taking a look :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants