From 5f2b087a149517100d731167678d21001c29817d Mon Sep 17 00:00:00 2001 From: Nikolay Yakimov Date: Sat, 4 May 2024 20:45:37 +0300 Subject: [PATCH] Fix images roundtripping through Markdown --- CHANGELOG.md | 13 +++- .../CrossRef/References/Blocks/Subfigures.hs | 9 +-- package.yaml | 2 +- pandoc-crossref.cabal | 2 +- test/m2m/emptyChapterLabels/expect.md | 8 +-- test/m2m/label-precedence/expect.md | 24 +------ .../listOfTemplates-buillet-list/expect.md | 72 +++---------------- test/m2m/listOfTemplates-ord-list/expect.md | 72 +++---------------- test/m2m/listOfTemplates/expect.md | 72 +++---------------- test/m2m/loxItemTitle/expect.md | 72 +++---------------- test/m2m/numberOverride/expect.md | 58 +++------------ test/m2m/secLabels/expect.md | 8 +-- test/m2m/setLabelAttribute/expect.md | 2 +- test/m2m/subfigures-ccsDelim/expect.md | 72 +++---------------- test/m2m/subfigures-grid/expect.md | 72 +++---------------- test/m2m/subfigures/expect.md | 72 +++---------------- test/m2m/titlesInRefs/expect.md | 8 +-- 17 files changed, 98 insertions(+), 540 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 730cadb1..8612c40c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,20 @@ +## 0.3.17.1 + +- Fix images roundtripping through Markdown + + Since a few versions ago, Makrdown images were not round-tripped properly. + This has been addressed. More information at + + ## 0.3.17.0 - Bump minimal pandoc version to 3.1.8 - Pandoc doesn't use hypertarget since 3.1.7, and inserts `label`s for named spans. This was messing with pandoc-crossref logic, hence required some changes. 3.1.7 has an unfortunate bug which prevents figures from working in LaTeX, hence the minimal version is 3.1.8. + Pandoc doesn't use hypertarget since 3.1.7, and inserts `label`s for named + spans. This was messing with pandoc-crossref logic, hence required some + changes. 3.1.7 has an unfortunate bug which prevents figures from working in + LaTeX, hence the minimal version is 3.1.8. - Bump dependencies for GHC to 9.6.2, bump GHC to 9.6.2 on CI for Linux and macOS diff --git a/lib-internal/Text/Pandoc/CrossRef/References/Blocks/Subfigures.hs b/lib-internal/Text/Pandoc/CrossRef/References/Blocks/Subfigures.hs index 5323a624..ab44eb2c 100644 --- a/lib-internal/Text/Pandoc/CrossRef/References/Blocks/Subfigures.hs +++ b/lib-internal/Text/Pandoc/CrossRef/References/Blocks/Subfigures.hs @@ -205,9 +205,10 @@ runFigure subFigure (label, cls, fattrs) (Caption short (btitle : rest)) content opts <- ask let label' = normalizeLabel label let title = blocksToInlines [btitle] - attrs = case blocksToInlines content of - [Image (_, _, as) _ _] -> fattrs <> as - _ -> fattrs + (attrs, content') = case blocksToInlines content of + [Image attr@(_, _, as) _ tgt] -> + (fattrs <> as, \capt -> [Plain [Image attr capt tgt]]) + _ -> (fattrs, const content) idxStr <- replaceAttr label' attrs title SPfxImg let title' | isLatexFormat opts = title @@ -216,5 +217,5 @@ runFigure subFigure (label, cls, fattrs) (Caption short (btitle : rest)) content replaceNoRecurse $ if subFigure && isLatexFormat opts then Plain $ latexSubFigure (head $ blocksToInlines content) label - else Figure (label,cls,setLabel opts idxStr fattrs) caption' content + else Figure (label,cls,setLabel opts idxStr fattrs) caption' (content' title') runFigure _ _ _ _ = noReplaceNoRecurse diff --git a/package.yaml b/package.yaml index f92e1fff..48aa2ae8 100644 --- a/package.yaml +++ b/package.yaml @@ -1,5 +1,5 @@ name: pandoc-crossref -version: '0.3.17.0' +version: '0.3.17.1' synopsis: Pandoc filter for cross-references description: pandoc-crossref is a pandoc filter for numbering figures, equations, tables and cross-references to them. diff --git a/pandoc-crossref.cabal b/pandoc-crossref.cabal index 998a657d..b8ab0b1c 100644 --- a/pandoc-crossref.cabal +++ b/pandoc-crossref.cabal @@ -5,7 +5,7 @@ cabal-version: 2.0 -- see: https://github.com/sol/hpack name: pandoc-crossref -version: 0.3.17.0 +version: 0.3.17.1 synopsis: Pandoc filter for cross-references description: pandoc-crossref is a pandoc filter for numbering figures, equations, tables and cross-references to them. category: Text diff --git a/test/m2m/emptyChapterLabels/expect.md b/test/m2m/emptyChapterLabels/expect.md index c82e49b2..663ab382 100644 --- a/test/m2m/emptyChapterLabels/expect.md +++ b/test/m2m/emptyChapterLabels/expect.md @@ -2,13 +2,7 @@ ## 1 Subsection {#sec:subsection label=""} -:::: {#fig:figure1 .figure} -![Figure1](./image.png) - -::: caption -Figure 1: Figure1 -::: -:::: +![Figure 1: Figure1](./image.png){#fig:figure1} ### 1.1 Subsubsection {#sec:subsubsection} diff --git a/test/m2m/label-precedence/expect.md b/test/m2m/label-precedence/expect.md index 4a342b60..230509a6 100644 --- a/test/m2m/label-precedence/expect.md +++ b/test/m2m/label-precedence/expect.md @@ -2,25 +2,13 @@ text -:::: {#fig:fig1 .figure} -![A figure](image.png) - -::: caption -Figure α: A figure -::: -:::: +![Figure α: A figure](image.png){#fig:fig1} ## \*.A Subsection {#subsection} other text -:::: {#fig:fig2 .figure} -![A figure with custom label](image.png){label="+"} - -::: caption -Figure +: A figure with custom label -::: -:::: +![Figure +: A figure with custom label](image.png){#fig:fig2 label="+"} ### \*.A.A Subsubsection {#subsubsection} @@ -28,13 +16,7 @@ text text text # B Custom on other elements {#custom-on-other-elements} -:::: {#fig:fig3 .figure} -![Figure](fig.png){label="F"} - -::: caption -Figure F: Figure -::: -:::: +![Figure F: Figure](fig.png){#fig:fig3 label="F"} ::: {#tbl:table label="T"} a b c diff --git a/test/m2m/listOfTemplates-buillet-list/expect.md b/test/m2m/listOfTemplates-buillet-list/expect.md index 5ea5f770..ac97ddf6 100644 --- a/test/m2m/listOfTemplates-buillet-list/expect.md +++ b/test/m2m/listOfTemplates-buillet-list/expect.md @@ -1,74 +1,20 @@ -:::: {#fig:1 .figure} -![1](fig1.png) +![Figure 1: 1](fig1.png){#fig:1} -::: caption -Figure 1: 1 -::: -:::: - -:::: {#fig:2 .figure} -![2](fig2.png) - -::: caption -Figure 2: 2 -::: -:::: - -:::: {#fig:3 .figure} -![3](fig3.png) - -::: caption -Figure 3: 3 -::: -:::: - -:::: {#fig:4 .figure} -![4](fig4.png) - -::: caption -Figure 4: 4 -::: -:::: +![Figure 2: 2](fig2.png){#fig:2} -:::: {#fig:5 .figure} -![5](fig5.png) +![Figure 3: 3](fig3.png){#fig:3} -::: caption -Figure 5: 5 -::: -:::: +![Figure 4: 4](fig4.png){#fig:4} -:::: {#fig:6 .figure} -![6](fig6.png) +![Figure 5: 5](fig5.png){#fig:5} -::: caption -Figure 6: 6 -::: -:::: +![Figure 6: 6](fig6.png){#fig:6} -:::: {#fig:7 .figure} -![7](fig7.png) - -::: caption -Figure 7: 7 -::: -:::: +![Figure 7: 7](fig7.png){#fig:7} -:::: {#fig:8 .figure} -![8](fig8.png) +![Figure 8: 8](fig8.png){#fig:8} -::: caption -Figure 8: 8 -::: -:::: - -:::: {#fig:9 .figure} -![9](fig9.png) - -::: caption -Figure 9: 9 -::: -:::: +![Figure 9: 9](fig9.png){#fig:9} # List of Figures diff --git a/test/m2m/listOfTemplates-ord-list/expect.md b/test/m2m/listOfTemplates-ord-list/expect.md index 44cb2f5d..29df54b3 100644 --- a/test/m2m/listOfTemplates-ord-list/expect.md +++ b/test/m2m/listOfTemplates-ord-list/expect.md @@ -1,74 +1,20 @@ -:::: {#fig:1 .figure} -![1](fig1.png) +![Figure 1: 1](fig1.png){#fig:1} -::: caption -Figure 1: 1 -::: -:::: - -:::: {#fig:2 .figure} -![2](fig2.png) - -::: caption -Figure 2: 2 -::: -:::: - -:::: {#fig:3 .figure} -![3](fig3.png) - -::: caption -Figure 3: 3 -::: -:::: - -:::: {#fig:4 .figure} -![4](fig4.png) - -::: caption -Figure 4: 4 -::: -:::: +![Figure 2: 2](fig2.png){#fig:2} -:::: {#fig:5 .figure} -![5](fig5.png) +![Figure 3: 3](fig3.png){#fig:3} -::: caption -Figure 5: 5 -::: -:::: +![Figure 4: 4](fig4.png){#fig:4} -:::: {#fig:6 .figure} -![6](fig6.png) +![Figure 5: 5](fig5.png){#fig:5} -::: caption -Figure 6: 6 -::: -:::: +![Figure 6: 6](fig6.png){#fig:6} -:::: {#fig:7 .figure} -![7](fig7.png) - -::: caption -Figure 7: 7 -::: -:::: +![Figure 7: 7](fig7.png){#fig:7} -:::: {#fig:8 .figure} -![8](fig8.png) +![Figure 8: 8](fig8.png){#fig:8} -::: caption -Figure 8: 8 -::: -:::: - -:::: {#fig:9 .figure} -![9](fig9.png) - -::: caption -Figure 9: 9 -::: -:::: +![Figure 9: 9](fig9.png){#fig:9} # List of Figures diff --git a/test/m2m/listOfTemplates/expect.md b/test/m2m/listOfTemplates/expect.md index 76047d2a..39b487f0 100644 --- a/test/m2m/listOfTemplates/expect.md +++ b/test/m2m/listOfTemplates/expect.md @@ -1,74 +1,20 @@ -:::: {#fig:1 .figure} -![1](fig1.png) +![Figure 1: 1](fig1.png){#fig:1} -::: caption -Figure 1: 1 -::: -:::: - -:::: {#fig:2 .figure} -![2](fig2.png) - -::: caption -Figure 2: 2 -::: -:::: - -:::: {#fig:3 .figure} -![3](fig3.png) - -::: caption -Figure 3: 3 -::: -:::: - -:::: {#fig:4 .figure} -![4](fig4.png) - -::: caption -Figure 4: 4 -::: -:::: +![Figure 2: 2](fig2.png){#fig:2} -:::: {#fig:5 .figure} -![5](fig5.png) +![Figure 3: 3](fig3.png){#fig:3} -::: caption -Figure 5: 5 -::: -:::: +![Figure 4: 4](fig4.png){#fig:4} -:::: {#fig:6 .figure} -![6](fig6.png) +![Figure 5: 5](fig5.png){#fig:5} -::: caption -Figure 6: 6 -::: -:::: +![Figure 6: 6](fig6.png){#fig:6} -:::: {#fig:7 .figure} -![7](fig7.png) - -::: caption -Figure 7: 7 -::: -:::: +![Figure 7: 7](fig7.png){#fig:7} -:::: {#fig:8 .figure} -![8](fig8.png) +![Figure 8: 8](fig8.png){#fig:8} -::: caption -Figure 8: 8 -::: -:::: - -:::: {#fig:9 .figure} -![9](fig9.png) - -::: caption -Figure 9: 9 -::: -:::: +![Figure 9: 9](fig9.png){#fig:9} ::: {#lst:code1 .listing .haskell} Listing 1: Listing caption 1 diff --git a/test/m2m/loxItemTitle/expect.md b/test/m2m/loxItemTitle/expect.md index 69aa4d76..10902ee5 100644 --- a/test/m2m/loxItemTitle/expect.md +++ b/test/m2m/loxItemTitle/expect.md @@ -1,74 +1,20 @@ -:::: {#fig:1 .figure} -![1](fig1.png) +![Figure 1: 1](fig1.png){#fig:1} -::: caption -Figure 1: 1 -::: -:::: - -:::: {#fig:2 .figure} -![2](fig2.png) - -::: caption -Figure 2: 2 -::: -:::: - -:::: {#fig:3 .figure} -![3](fig3.png) - -::: caption -Figure 3: 3 -::: -:::: - -:::: {#fig:4 .figure} -![4](fig4.png) - -::: caption -Figure 4: 4 -::: -:::: +![Figure 2: 2](fig2.png){#fig:2} -:::: {#fig:5 .figure} -![5](fig5.png) +![Figure 3: 3](fig3.png){#fig:3} -::: caption -Figure 5: 5 -::: -:::: +![Figure 4: 4](fig4.png){#fig:4} -:::: {#fig:6 .figure} -![6](fig6.png) +![Figure 5: 5](fig5.png){#fig:5} -::: caption -Figure 6: 6 -::: -:::: +![Figure 6: 6](fig6.png){#fig:6} -:::: {#fig:7 .figure} -![7](fig7.png) - -::: caption -Figure 7: 7 -::: -:::: +![Figure 7: 7](fig7.png){#fig:7} -:::: {#fig:8 .figure} -![8](fig8.png) +![Figure 8: 8](fig8.png){#fig:8} -::: caption -Figure 8: 8 -::: -:::: - -:::: {#fig:9 .figure} -![9](fig9.png) - -::: caption -Figure 9: 9 -::: -:::: +![Figure 9: 9](fig9.png){#fig:9} ::: {#lst:code1 .listing .haskell} Listing 1: Listing caption 1 diff --git a/test/m2m/numberOverride/expect.md b/test/m2m/numberOverride/expect.md index 30857771..f81751a3 100644 --- a/test/m2m/numberOverride/expect.md +++ b/test/m2m/numberOverride/expect.md @@ -2,62 +2,22 @@ ## 1.1 Earlier Subsection -:::: {#fig:img1 .figure} -![Image 1](img2.png) - -::: caption -Figure 1.1.1: Image 1 -::: -:::: +![Figure 1.1.1: Image 1](img2.png){#fig:img1} ## 1.6 Title of Subsection {#title-of-subsection number="6"} -:::: {#fig:img2 .figure} -![Image 1.6.2](img2.png) - -::: caption -Figure 1.6.1: Image 1.6.2 -::: -:::: - -:::: {#fig:img3 .figure} -![Image 1.6.100500](img2.png){number="100500"} - -::: caption -Figure 1.6.100500: Image 1.6.100500 -::: -:::: +![Figure 1.6.1: Image 1.6.2](img2.png){#fig:img2} -:::: {#fig:img4 .figure} -![Image 1.6.100501](img2.png) +![Figure 1.6.100500: Image 1.6.100500](img2.png){#fig:img3 +number="100500"} -::: caption -Figure 1.6.100501: Image 1.6.100501 -::: -:::: +![Figure 1.6.100501: Image 1.6.100501](img2.png){#fig:img4} ## 1.7 Title of Subsection -:::: {#fig:img21 .figure} -![Image 1.7.1](img2.png) - -::: caption -Figure 1.7.1: Image 1.7.1 -::: -:::: - -:::: {#fig:img31 .figure} -![Image 1.7.100500](img2.png){number="100500"} - -::: caption -Figure 1.7.100500: Image 1.7.100500 -::: -:::: +![Figure 1.7.1: Image 1.7.1](img2.png){#fig:img21} -:::: {#fig:img41 .figure} -![Image 1.7.100501](img2.png) +![Figure 1.7.100500: Image 1.7.100500](img2.png){#fig:img31 +number="100500"} -::: caption -Figure 1.7.100501: Image 1.7.100501 -::: -:::: +![Figure 1.7.100501: Image 1.7.100501](img2.png){#fig:img41} diff --git a/test/m2m/secLabels/expect.md b/test/m2m/secLabels/expect.md index 1d52fb20..19a6c533 100644 --- a/test/m2m/secLabels/expect.md +++ b/test/m2m/secLabels/expect.md @@ -2,13 +2,7 @@ ## a.a Second Level Section {#second-level-section} -:::: {#fig:myfig .figure} -![my figure](myfig.png) - -::: caption -Figure a: my figure -::: -:::: +![Figure a: my figure](myfig.png){#fig:myfig} ## a.b Other Second Level Section {#other-second-level-section} diff --git a/test/m2m/setLabelAttribute/expect.md b/test/m2m/setLabelAttribute/expect.md index cbcf289f..cd6b9c3e 100644 --- a/test/m2m/setLabelAttribute/expect.md +++ b/test/m2m/setLabelAttribute/expect.md @@ -1,7 +1,7 @@ # Section {#section label="1"} :::: {#fig:1 .figure label="1.1"} -![Figure](./image.png) +![Figure 1.1: Figure](./image.png) ::: caption Figure 1.1: Figure diff --git a/test/m2m/subfigures-ccsDelim/expect.md b/test/m2m/subfigures-ccsDelim/expect.md index f75b5f71..9902737f 100644 --- a/test/m2m/subfigures-ccsDelim/expect.md +++ b/test/m2m/subfigures-ccsDelim/expect.md @@ -14,77 +14,23 @@ Figure 1: Caption. a --- 1; b --- 2; c --- 3; d --- 4; e --- 5; f --- :::: :::: {#fig:subfigures2 .figure .subfigures} -:::: {#fig:subfig21 .figure} -![1](fig1.png) +![a](fig1.png){#fig:subfig21} -::: caption -a -::: -:::: - -:::: {#fig:subfig22 .figure} -![2](fig2.png) - -::: caption -b -::: -:::: - -:::: figure -![3](fig3.png) - -::: caption -c -::: -:::: - -:::: {#fig:subfig24 .figure} -![4](fig4.png) - -::: caption -d -::: -:::: +![b](fig2.png){#fig:subfig22} -:::: figure -![5](fig5.png) +![c](fig3.png) -::: caption -e -::: -:::: - -:::: {#fig:subfig26 .figure} -![6](fig6.png) - -::: caption -f -::: -:::: - -:::: {#fig:subfig27 .figure} -![7](fig7.png) +![d](fig4.png){#fig:subfig24} -::: caption -g -::: -:::: +![e](fig5.png) -:::: figure -![8](fig8.png) +![f](fig6.png){#fig:subfig26} -::: caption -h -::: -:::: +![g](fig7.png){#fig:subfig27} -:::: {#fig:subfig29 .figure} -![9](fig9.png) +![h](fig8.png) -::: caption -i -::: -:::: +![i](fig9.png){#fig:subfig29} ::: caption Figure 2: Caption. a --- 1; b --- 2; c --- 3; d --- 4; e --- 5; f --- diff --git a/test/m2m/subfigures-grid/expect.md b/test/m2m/subfigures-grid/expect.md index 3aba5eb7..8d592526 100644 --- a/test/m2m/subfigures-grid/expect.md +++ b/test/m2m/subfigures-grid/expect.md @@ -41,77 +41,23 @@ g --- 7, h --- 8, i --- 9 :::: {#fig:subfigures2 .figure .subfigures} +:--------------------------------------------------------------------:+ -| :::: {#fig:subfig21 .figure} | -| ![1](fig1.png) | -| | -| ::: caption | -| a | -| ::: | -| :::: | +| ![a](fig1.png){#fig:subfig21} | +----------------------------------------------------------------------+ -| :::: {#fig:subfig22 .figure} | -| ![2](fig2.png) | -| | -| ::: caption | -| b | -| ::: | -| :::: | +| ![b](fig2.png){#fig:subfig22} | +----------------------------------------------------------------------+ -| :::: figure | -| ![3](fig3.png) | -| | -| ::: caption | -| c | -| ::: | -| :::: | +| ![c](fig3.png) | +----------------------------------------------------------------------+ -| :::: {#fig:subfig24 .figure} | -| ![4](fig4.png) | -| | -| ::: caption | -| d | -| ::: | -| :::: | +| ![d](fig4.png){#fig:subfig24} | +----------------------------------------------------------------------+ -| :::: figure | -| ![5](fig5.png) | -| | -| ::: caption | -| e | -| ::: | -| :::: | +| ![e](fig5.png) | +----------------------------------------------------------------------+ -| :::: {#fig:subfig26 .figure} | -| ![6](fig6.png) | -| | -| ::: caption | -| f | -| ::: | -| :::: | +| ![f](fig6.png){#fig:subfig26} | +----------------------------------------------------------------------+ -| :::: {#fig:subfig27 .figure} | -| ![7](fig7.png) | -| | -| ::: caption | -| g | -| ::: | -| :::: | +| ![g](fig7.png){#fig:subfig27} | +----------------------------------------------------------------------+ -| :::: figure | -| ![8](fig8.png) | -| | -| ::: caption | -| h | -| ::: | -| :::: | +| ![h](fig8.png) | +----------------------------------------------------------------------+ -| :::: {#fig:subfig29 .figure} | -| ![9](fig9.png) | -| | -| ::: caption | -| i | -| ::: | -| :::: | +| ![i](fig9.png){#fig:subfig29} | +----------------------------------------------------------------------+ ::: caption diff --git a/test/m2m/subfigures/expect.md b/test/m2m/subfigures/expect.md index 46b8a1cb..b8b548ba 100644 --- a/test/m2m/subfigures/expect.md +++ b/test/m2m/subfigures/expect.md @@ -14,77 +14,23 @@ g --- 7, h --- 8, i --- 9 :::: :::: {#fig:subfigures2 .figure .subfigures} -:::: {#fig:subfig21 .figure} -![1](fig1.png) +![a](fig1.png){#fig:subfig21} -::: caption -a -::: -:::: - -:::: {#fig:subfig22 .figure} -![2](fig2.png) - -::: caption -b -::: -:::: - -:::: figure -![3](fig3.png) - -::: caption -c -::: -:::: - -:::: {#fig:subfig24 .figure} -![4](fig4.png) - -::: caption -d -::: -:::: +![b](fig2.png){#fig:subfig22} -:::: figure -![5](fig5.png) +![c](fig3.png) -::: caption -e -::: -:::: - -:::: {#fig:subfig26 .figure} -![6](fig6.png) - -::: caption -f -::: -:::: - -:::: {#fig:subfig27 .figure} -![7](fig7.png) +![d](fig4.png){#fig:subfig24} -::: caption -g -::: -:::: +![e](fig5.png) -:::: figure -![8](fig8.png) +![f](fig6.png){#fig:subfig26} -::: caption -h -::: -:::: +![g](fig7.png){#fig:subfig27} -:::: {#fig:subfig29 .figure} -![9](fig9.png) +![h](fig8.png) -::: caption -i -::: -:::: +![i](fig9.png){#fig:subfig29} ::: caption Figure 2: Caption. a --- 1, b --- 2, c --- 3, d --- 4, e --- 5, f --- 6, diff --git a/test/m2m/titlesInRefs/expect.md b/test/m2m/titlesInRefs/expect.md index 058b4b53..7963fea3 100644 --- a/test/m2m/titlesInRefs/expect.md +++ b/test/m2m/titlesInRefs/expect.md @@ -1,12 +1,6 @@ # Section {#sec:section} -:::: {#fig:figure .figure} -![A Figure](figure.png) - -::: caption -Figure 1: A Figure -::: -:::: +![Figure 1: A Figure](figure.png){#fig:figure} sec. 1 (Section)