filter - 是否可以在 pandoc 过滤器上启用扩展?
问题描述
我正在尝试制作一个过滤器,将 org-mode 的某些功能转换为 GitLab-markdown(Pandoc 开箱即用不支持),特别是数学块。
过滤器在转换为 时应该起作用markdown
,但不是为数学块(由 括起来$$...$$
)提供降价格式,它应该将块写为
``` math
a + b = c
```
我现在的前言是
在 org-mode 中,数学块只是乳胶代码:
\begin{equation}
a + b = c
\end{equation}
RawBlock
这被解析为带有 format的 pandoc AST latex
。然后我删除第一行 () 和\begin{equation}
最后一行 ( \end{equation}
),并构造一个CodeBlock
带有 attributes 的 pandoc {"math"}
,因此CodeBlock
对象在 AST 中显示为
CodeBlock ("",["math"],[]) "a + b = c\n"
然后我让Pandoc创建markdown文档,写出来的结果是
``` {.math}
a + b = c
```
问题:
我想要裸露的math
,不{.math}
写的,不使用 CLI 选项。
我知道这可以通过将 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('``` math\n%s\n```\n', text)
)
所以你基本上是自己创建 Markdown,这在代码块的情况下是相对安全的(假设数学不包含```
,这将是非常不寻常的)。
至于最初的问题:目前无法在过滤器中启用扩展或选项。
推荐阅读
- c - 为什么使用结构标签名称打印结构的第一个成员并为字符成员使用 %d 说明符会导致奇怪的输出?
- node.js - 使用 AWS Lambda 和 API Gateway NodeJs 的格式错误的 Lambda 代理响应
- reactjs - 手动输入日期时,KeyboardDatePicker 减去 1 天
- javascript - 画布上的绘图点在 Safari 上不起作用
- swift - 如何将 JavaScript 正则表达式转换为 Swift 以进行电子邮件验证?
- sql - sql plus中条件调用sql脚本
- c# - FileSystemWatcher:忽略自己的进程所做的更改
- function - 如何在 Rust 中实现多级柯里化函数?
- html - 暗模式下的电子邮件呈现
- android - 如何在android中使用具有模糊效果CardView的自定义阴影