ConTeXt, KeenWrite, Markdown, and XHTML
How would you convert the first class attribute of XHTML div elements to ConTeXt LMTX-specific start/stop environments? For example: <div class="poem dark"> <div class="stanza"> Whose woods these are I think I know. </div> <div class="stanza"> And miles to go before I sleep. </div> </dv> Becomes (the equivalent of?): \startpoem \startstanza Whose woods these are I think I know. \stopstanza \startstanza And miles to go before I sleep. \stopstanza \stoppoem In case this is an XY problem, background details follow. In a nutshell: convert a processed Markdown file that includes interpolated variables, arbitrary classes, and output from R functions into a format that ConTeXt can typeset. Background Details Pandoc's fenced div syntax is now supported by my text editor, allowing users to write "paragraph classes" in Markdown, such as: ::: {.poem .dark} ::: stanza Whose woods these are I think I know. ::: ::: This gets converted to XHTML (as shown above), which is to be rendered using ConTeXt LMTX. Rendering via ConTeXt needs the following tool chain: Editor (.md) -> run Pandoc (.tex) -> run ConTeXt (.pdf) Generating XHTML means Pandoc can be removed, simplifying the chain: Editor (.md -> magic -> .xhtml) -> run ConTeXt (.pdf) The Lua code to generate start/stop environments with Pandoc is described in Part 8 of my Typesetting Markdown series. https://dave.autonoma.ca/blog/2020/04/28/typesetting-markdown-part-8/#annota... The XML-MKIV documentation shows how to map a specific setup to a particular attribute: \xmlsetsetup{demo}{resource[@type='figure']}{xml:demo:figure} In Schmitz' XHTML-oriented My Way from 2010 there's a getmeas Lua function defined on page 9 that parses a width attribute. That's great for the opening div, but how would you close/stop the correct environment for nested divs? Would ConTeXt automatically track these on a stack, for example? Additional Ideas Given that the text editor converts Markdown to XHTML and has an XSLT engine, the following is possible: Editor (.md -> .xhtml) -> XSLT (.tex) -> run ConTeXt (.pdf) Piping XHTML directly into ConTeXt would be ideal, though. Well, piping CommonMark plus fenced div extensions to ConTeXt would be optimal, but my understanding is that support isn't quite there yet. Aditya wrote a Markdown filter that runs: pandoc -t context -o \externalfilteroutputfile\space \externalfilterinputfile This still needs Pandoc, though. There's also a dependency-free Markdown module. A few problems though. First, the module isn't ported to ConTeXt LMTX, yet? Second, it doesn't support element attributes beyond enabling content slicing. (Third, the module has LaTeX support tightly bundled within, which bloats a pure ConTeXt solution.) Related Links https://dl.contextgarden.net/myway/tas/xhtml.pdf https://www.pragma-ade.com/general/manuals/xml-mkiv.pdf https://github.com/DaveJarvis/keenwrite#screenshots https://github.com/adityam/filter/blob/master/README.md https://mirror.its.dal.ca/ctan/macros/generic/markdown/markdown.html#header-... https://github.com/Witiko/markdown/
participants (1)
-
Thangalin