Skip to content

Commit

Permalink
Fix images roundtripping through Markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
lierdakil committed May 4, 2024
1 parent 2dfb0d5 commit 5f2b087
Show file tree
Hide file tree
Showing 17 changed files with 98 additions and 540 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
<https://github.com/jgm/pandoc/issues/9720>

## 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pandoc-crossref.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions test/m2m/emptyChapterLabels/expect.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down
24 changes: 3 additions & 21 deletions test/m2m/label-precedence/expect.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,21 @@

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}

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
Expand Down
72 changes: 9 additions & 63 deletions test/m2m/listOfTemplates-buillet-list/expect.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
72 changes: 9 additions & 63 deletions test/m2m/listOfTemplates-ord-list/expect.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
72 changes: 9 additions & 63 deletions test/m2m/listOfTemplates/expect.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading

0 comments on commit 5f2b087

Please sign in to comment.