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

如何在Quarto添加交叉引用后运行Lua过滤器?

在Quarto添加交叉引用后运行Lua过滤器的方法

Quarto默认的Lua过滤器会在交叉引用处理前执行,要让过滤器在图题前缀(如Figure 1:)添加后运行,只需调整过滤器的执行阶段:

1. 指定过滤器运行阶段

方式一:命令行指定

渲染文档时,通过--post-refs参数让过滤器在交叉引用处理完成后运行:

quarto render your-document.qmd --lua-filter=your-filter.lua --post-refs

方式二:在_quarto.yml中配置

在项目配置文件里给过滤器指定phase: post-refs,每次渲染都会自动应用:

filters:
  - your-filter.lua:
      phase: post-refs

2. 编写处理图题的Lua过滤器示例

下面是实现「Figure X:」部分加粗的过滤器代码,可直接修改使用:

function Image(img)
  local caption = img.caption
  -- 检查标题结构是否匹配「Figure + 编号 + :」的格式
  if #caption >= 5 
    and caption[1].text == "Figure" 
    and caption[3].text:match("^%d+$") 
    and caption[4].text == ":" 
  then
    -- 将图题前缀(Figure、编号、冒号及后续空格)转为加粗格式
    local bold_prefix = pandoc.Strong({
      caption[1], caption[2], caption[3], caption[4], caption[5]
    })
    -- 重新组合标题:加粗前缀 + 原有标题内容
    img.caption = pandoc.Inlines({bold_prefix}) .. caption:sub(6)
  end
  return img
end

3. 验证效果

运行quarto render your-document.qmd --native查看处理后的AST,确认图题前缀已被添加,且过滤器执行后对应的节点已被包裹为Strong类型。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.13 05:25:40