max-heller / mdbook-pandoc

A mdbook backend powered by Pandoc.
Apache License 2.0
96 stars 7 forks source link

Pre-processing breaks filter syntax #91

Closed aiwell-ac5000 closed 2 months ago

aiwell-ac5000 commented 3 months ago

Using a filter like pandoc-crossref becomes impossible because pre-processing adds \ to brackets. Syntax like [Prefix @fig:1] and [-@fig:1] breaks.

max-heller commented 2 months ago

This is a result of mdbook-pandoc using pulldown-cmark-to-cmark to render parsed Markdown back to text:

#[test]
fn square_brackets() {
    let input = "[Prefix @fig:1] [-@fig:1]";
    let parsed = pulldown_cmark::Parser::new(input);
    let mut output = String::new();
    pulldown_cmark_to_cmark::cmark(parsed, &mut output).unwrap();
    assert_eq!(output, "\\[Prefix @fig:1\\] \\[-@fig:1\\]");
}

In order for your example to work, pulldown-cmark-to-cmark would have to leave the square brackets as-is. It looks like https://github.com/Byron/pulldown-cmark-to-cmark/pull/71 actually adds support for this in the form of an alternative formatting function, I can try it out once it merges and they publish a new release.

However, since the new function that preserves escapes is opt-in, it's likely that other mdbook preprocessors would still break your use case. In general, mdbook-pandoc does not aim to support all of Pandoc's features for mdbooks--it's focus is to support mdbook's Commonmark-based Markdown spec. Some Pandoc extensions might work "for free", but others like this one may not.

max-heller commented 2 months ago

Hi @aiwell-ac5000, can you verify that #95 supports your use case?

cargo install --git https://github.com/max-heller/mdbook-pandoc.git mdbook-pandoc

EDIT: Closing as completed since testing suggests your use case should work, but let me know if it doesn't

aiwell-ac5000 commented 2 months ago

Can confirm that it worked.