我正在尝试制作一个过滤器,将组织模式的一些功能转换为GitLab markdown(Pandoc不支持开箱即用(,特别是数学块。
当转换为markdown
时,过滤器应该工作,但它不应该为数学块(由$$...$$
包围(提供标记格式,而是应该将块写入
``` math
a + b = c
```
我现在的课程是
在组织模式中,数学块只是乳胶代码:
begin{equation}
a + b = c
end{equation}
这被解析为具有格式CCD_ 4的pandoc AST CCD_。然后,我删除第一行(begin{equation}
(和最后一行(end{equation}
(,并用{"math"}
构建一个pandocCodeBlock
,因此CodeBlock
对象在AST中显示为
CodeBlock ("",["math"],[]) "a + b = cn"
然后我让Pandoc创建降价文档,写出来的结果是
``` {.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
您可以通过自己创建所需的块来完全控制输出。
例如,你可以写而不是local cb = pandoc.CodeBlock()
ff
return pandoc.RawBlock('markdown',
string.format('``` mathn%sn```n', text)
)
因此,您基本上是自己创建Markdown,这在代码块的情况下是相对安全的(假设数学不包含```
,这将是非常不寻常的(。
至于最初的问题:在过滤器中启用扩展或选项目前是不可能的。