背景
工具链目前使用 Pandoc 和 Lua 过滤器来生成通用 ConTeXt 环境。我的文本编辑器生成符合 Pandoc 扩展的 XHTML 文档围栏分区语法。请考虑以下 Markdown 片段:
::: {.poem .dark}
::: stanza
Whose woods these are I think I know.
:::
::: stanza
And miles to go before I sleep.
:::
:::
Lua 过滤器的详细描述请见第 8 部分我的排版 Markdown系列。在片段上运行 pandoc 会产生:
\startpoem
\startstanza
Whose woods these are I think I know.
\stopstanza
\startstanza
And miles to go before I sleep.
\stopstanza
\stoppoem
我想从工具链中消除 Pandoc,以便文本编辑器可以直接与 ConTeXt 互操作(即不依赖 Pandoc)。
问题
考虑以下代码片段:
\startxmlsetups xml:div
% Writes "poem" (or "stanza")
\xmlatt{#1}{class}
\xmlflush{#1}
% Writes "poem" (or "stanza")
\xmlatt{#1}{class}
\stopxmlsetups
安装程序必须运行与以下内容等效的任何内容,而不是将“诗歌”写入文档:
\startxmlsetups xml:div
\startpoem
\xmlflush{#1}
\stoppoem
\stopxmlsetups
例如,类似这样的内容:
\startxmlsetups xml:div
\ctxlua{ context( "\\start" .. \xmlatt{#1}{class} )}
\xmlflush{#1}
\ctxlua{ context( "\\stop" .. \xmlatt{#1}{class} )}
\stopxmlsetups
或者也许使用变量?例如:
\startxmlsetups xml:div
\setvariable{xhtml}{class}{\xmlatt{#1}{class}}
\startluacode
local value = "\\start" .. tokens.getters.macro( tokens.getters.macro( "??variables" ) .. "xhtml:class" )
context( value )
\stopluacode
\xmlflush{#1}
\startluacode
local value = "\\stop" .. tokens.getters.macro( tokens.getters.macro( "??variables" ) .. "xhtml:class" )
context( value )
\stopluacode
\stopxmlsetups
问题
如何在 xmlsetups 块中将 XHTML div 元素的任意类属性转换为 ConTeXt LMTX 特定的启动/停止环境?
答案1
只使用怎么样\start[\xmlatt{#1}{class}]
?这是完整的示例(抱歉,没有费心为诗歌和诗节想出更好的映射)。
\startbuffer[xml-data]
<div class="poem">
<div class="stanza">
Whose woods these are I think I know.
</div>
<div class="stanza">
And miles to go before I sleep.
</div>
</div>
\stopbuffer
\defineframedtext
[poem]
[
width=\textwidth,
]
\definestartstop[stanza][style=bold, after=\blank]
\startxmlsetups xml:xhtml
\xmlsetsetup{#1}{div}{xml:div}
\stopxmlsetups
\xmlregisterdocumentsetup{xhtml}{xml:xhtml}
\startxmlsetups xml:div
\start[\xmlatt{#1}{class}]
\xmlflush{#1}
\stop
\stopxmlsetups
\starttext
\xmlprocessbuffer{xhtml}{xml-data}{}
\stoptext