pandoc / lua-filters

A collection of lua filters for pandoc
MIT License
611 stars 166 forks source link

Fix table-short-captions support for Pandoc 2.10+ #149

Closed smancill closed 3 years ago

smancill commented 3 years ago

Support for Pandoc 2.10 is not working, and all the tests are broken too, they do not check anything.

This PR fixes Pandoc 2.10 support, and also fixes the tests to ensure they do run (and updates them to the changes introduced by 7a49118).

Commit 6e1b2cc introduced support for Pandoc 2.10 but it doesn't work because it treats the new Table.caption.long object as the pre 2.10 Table.caption object, but they are completely different lists. Table.caption.long is a list of Blocks, where each block has a content key which is a List of inlines (or it should be, a test would be needed for more complex captions?). The pre 2.10 Table.caption is a List of inlines, so they cannot share the same code to be manipulated.

This PR fixes it by just splitting the code into two different functions. They do follow the same structure, but it is better to keep them separated, otherwise it would require too many ifs, or code that is not clear.

For pre 2.10 Table.caption just keep the code as it is. For the new Table.caption.long, ensure the outer list of Blocks is taken into account when searching for the inline Span with the short caption.

Now all test do run and all pass, with pre and post Pandoc 2.10 (nix-run-version is a helper that allows me to use nixpkgs releases to run different versions of a command)

Before this PR (well, not really, this PR also fixes the tests to see them failing. Before the last commit fixing 2.10 support):

nix-run-version 19.09 pandoc make && echo "no errors"
pandoc 2.7.3
Compiled with pandoc-types 1.17.6, texmath 0.11.2.2, skylighting 0.8.2
no errors

$ nix-run-version 20.09 pandoc make && echo "no errors"
pandoc 2.10.1
Compiled with pandoc-types 1.21, texmath 0.12.0.2, skylighting 0.8.5
Output does not contain `\def\pandoctableshortcapt{}  % .unlisted`.
make: *** [test] Error 1

With this PR:

$ nix-run-version 19.09 pandoc make && echo "no errors"
pandoc 2.7.3
Compiled with pandoc-types 1.17.6, texmath 0.11.2.2, skylighting 0.8.2
no errors

$ nix-run-version 20.09 pandoc make && echo "no errors"
pandoc 2.10.1
Compiled with pandoc-types 1.21, texmath 0.12.0.2, skylighting 0.8.5
no errors

$ nix-run-version unstable pandoc make && echo "no errors"
pandoc 2.11.2
Compiled with pandoc-types 1.22, texmath 0.12.0.3, skylighting 0.10.0.3,
citeproc 0.2, ipynb 0.1.0.1
no errors
smancill commented 3 years ago

@blake-riley please review.

smancill commented 3 years ago

Agh, it works with every Pandoc version I tried on my Mac. I need to figure out why the CI is failing.

smancill commented 3 years ago

Rebased to fix the CI ($(</dev/stdin) was not working so I went back to $(cat -)).