Open argent0 opened 3 years ago
Very interesting indeed. Ironically this (at least the implicit syntax) is almost exactly the same input markdown I conjured up for a book project just 3 days ago. I didn't prefix the class name with a dot but that's the only difference in input. Since the details of my production workflow are completely different and I don't want to distract too much from this issue I'll hide them away here, the curious can click for details.
Obviously my implementation is just overloading the block syntax without introducing a new AST element. This works because of the flexibility I have on the typesetter side but may or may not work well for all output formats. There are pros and cons to overloading an existing object and giving it "magic" smarts vs. having a dedicated content type.
Back to your filter (and your Pandoc fork). I'm not sure we want to merge anything here that doesn't work out of the box with Pandoc, but I'm very interested in seeing something worked out that makes this easier on everybody. I'd be happy to play along with other implementations in the name of keeping things standardized and hence inter-operable if possible.
What are your thoughts on the Pandoc fork? Has the idea of a new AST object for this been brought up yet?
Yes, the idea for a new AST object is being discussed since 2016. There have been concrete proposals before our work, that I've merged into my fork.
We are working on improving pandoc's figure support and keep public online discussions . We mainly focus on HTML, LaTeX and Markdown.
So my fork includes the Figure
AST element. And most output formats can handle it. On the input side we've decided to go with this method for markdown (which doesn't have support for floats yet) and I'm working on the HTML input (the <figure>
tag, which is currently handled in a limited fashion).
<figure class="important">
<ul> <li> Delete me? </li> </ul>
<figcaption> CAP2 </figcaption>
</figure>
Pandoc 2.14
$ pandoc -f html -t native test/figures/figure-simple.html
[BulletList
[[Plain [Str "Delete",Space,Str "me?"]]]
,Para [Str "CAP2"]]
$ pandoc -f html -t html test/figures/figure-simple.html
<ul>
<li>Delete me?</li>
</ul>
<p>CAP2</p>
My Fork
$ pandoc-fork -f html+native_figures -t native test/figures/figure-simple.html
[Figure ("",["important"],[]) (Caption Nothing [Plain [Str "CAP2"]]) [BulletList [[Plain [Str "Delete",Space,Str "me?"]]]]]
$ pandoc-fork -f html+native_figures -t html test/figures/figure-simple.html
<figure class="important">
<ul>
<li>Delete me?</li>
</ul>
<figcaption>CAP2</figcaption>
</figure>
Thoughts
An ad hoc Figure AST element (which should be understood as a float) will improve consistency and flexibility in many output formats.
This PR requires a
Figure
constructor in pandoc's AST.The code for a pandoc fork that has such constructor can be found here.
Details
This filter provides two syntaxs to represent figures in markdown.
Explicit syntax
The explicit syntax is constructed using a
div
with "figure" class. The caption is also specified using adiv
but with a "caption" class.Here is an example.
All elements inside the figure that are an image without a caption in its own paragraph become html's
img
tags.Here is an example of figure containing two images and a caption.
This will result in a single figure containing multiple images.
This will result in a single figure containing multiple images.
Implicit syntax
The second syntax uses the last paragraph inside the figure as the caption.
This results in the following output:
Sample Firefox's HTML rendering
For the implicit syntax example, this is firefox's render.