You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改Pandoc Lua过滤器保留链接文本与方括号为NormalCitation

解决Pandoc Lua过滤器保留链接文本与方括号为NormalCitation的问题

需求:将带有x-devonthink-item://前缀的Markdown链接,转换为带方括号的文本,作为Pandoc的NormalCitation格式。例如:

原内容:

[@a-local-file, page 15](x-devonthink-item://742BD8FE-B962-422F-98C1-B1K4DQA5A117?page=15)

期望转换结果:

[@a-local-file, page 15]

原尝试的Lua过滤器仅返回纯文本@a-local-file, page 15,直接添加方括号会被识别为AuthorInText,不符合需求。

修改后的Lua过滤器代码

function Link(el)
    if el.target:find("^x%-devonthink%-item://") then
        -- 把链接内容转为字符串,包裹方括号后以RawInline形式返回
        local citation_content = "[" .. pandoc.utils.stringify(el.content) .. "]"
        return pandoc.RawInline("markdown", citation_content)
    end
end

代码说明

  • 使用pandoc.utils.stringify(el.content)将链接内的Inline元素转换为纯字符串;
  • 用方括号包裹该字符串,构造出符合NormalCitation格式的文本;
  • 通过pandoc.RawInline("markdown", ...)将这段文本以Markdown原生格式返回,让Pandoc直接解析为NormalCitation,而非普通文本或其他引用类型。

内容的提问来源于stack exchange,提问作者TomBen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 00:21:26