[英]Is it posible to enable extensions on pandoc filters?
我正在尝试制作一个过滤器以将 org-mode 的某些功能转换为 GitLab-markdown(Pandoc 开箱即用不支持),特别是数学块。
过滤器在转换为markdown
时应该起作用,但不是为数学块提供 markdown 格式(由$$...$$
括起来),它应该将块写为
``` math
a + b = c
```
我现在的前言是
在 org 模式下,数学块只是 latex 代码:
\begin{equation}
a + b = c
\end{equation}
这被解析为格式为latex
RawBlock
然后我删除第一行( \begin{equation}
)和最后一行( \end{equation}
),并构造一个带有属性{"math"}
的 pandoc CodeBlock
,因此CodeBlock
object 在 AST 中显示为
CodeBlock ("",["math"],[]) "a + b = c\n"
然后我让Pandoc创建markdown文档,写出来的结果是
``` {.math}
a + b = c
```
问题:
我想要在不使用 CLI 选项的情况下编写裸math
,而不是编写{.math}
。
我知道这可以通过将 Writer 扩展fenced_code_attributes
设置为 false 来完成(例如$pandoc -w markdown-fenced_code_attributes...
),但我更希望在过滤器内完成此操作。
或者是否可以在过滤器内设置扩展?
这是我尝试过的lua过滤器:
function split(str,pat)
local tbl = {}
str:gsub(pat, function(x) tbl[#tbl+1]=x end)
return tbl
end
function RawBlock(rb)
if rb.format == "latex" then
local text = rb.text
split_text = split(text, "[^\n]*")
if split_text[1] == '\\begin{equation}' and split_text[#split_text-1] == '\\end{equation}' then
table.remove(split_text, #split_text-1)
table.remove(split_text, 1)
text = table.concat(split_text, "\n")
local cb = pandoc.CodeBlock()
cb.attr = {"",{"math"}}
cb.text = text
return cb
end
end
end
您可以通过自己创建所需的块来完全控制 output。
例如,代替local cb = pandoc.CodeBlock()
ff.,你可以写
return pandoc.RawBlock('markdown',
string.format('``` math\n%s\n```\n', text)
)
所以你基本上会自己创建 Markdown,这在代码块的情况下是相对安全的(假设数学不包含```
,这将是非常不寻常的)。
至于最初的问题:目前无法在过滤器中启用扩展或选项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.