-
-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add markdown figure filters. #187
base: master
Are you sure you want to change the base?
Conversation
b0a6556
to
50cbeba
Compare
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. Sample implementation typesetting figures from Markdown in SILEFor my use case I didn't use a filter at all, but I am using the SILE writer in my Pandoc fork. This writer just takes the div syntax and outputs block wrappers based on the classes, so basically what I get in SILE is a Markdown input: ::: figure
![Grossmünster Katedrali](resimler/grossmunster.jpg)
*Huldrych Zwingli’nin 1519–1531 yılları arasında vaaz verdiği İsviçre Zürih’teki Grossmünster Katedrali.*
::: Gets converted to SIL format thus:
To typeset this I have a Lua function in the project for the figure class that makes assumptions about how to layout the figures for that book. It overrides the image function to make the images the full frame width and centers everything on the page: SILE.registerCommand("class:figure", function (options, content)
local old_img = SILE.Commands["img"]
SILE.registerCommand("img", function (options, content)
options.width = "100%fw"
old_img(options, content)
SILE.call("skip", { height = "1en" })
end)
SILE.call("open-double-page", { double = true, odd = false })
SILE.call("topfill")
SILE.call("vfill")
SILE.call("center", {}, function ()
SILE.process(content)
end)
SILE.Commands["img"] = old_img
end) The finished result is this page: 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
Pandoc 2.14
My Fork
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. Thecaption is also specified using a
div
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.