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

如何在Quarto网站中添加可折叠摘要框?

在Quarto网站中添加出版物可折叠摘要框的实现方法

功能别称参考

这个功能在Quarto/Markdown生态里常被称为「折叠面板」「可折叠区块」,或者对应Bootstrap的「collapse组件」,用这些关键词搜资料会更高效。

方法1:Quarto原生折叠块(最省心)

Quarto自带折叠块语法,直接用包裹标签就能实现,不用额外加依赖:

---
title: "Research"
---

### Publications

------------------------------------------------------------------------

#### 2022

Authors. Year. ["Title".](https://stackoverflow.com/) *Journal*
::: {.collapse}
::: {.collapse-toggle}点击查看摘要
:::
::: {.collapse-content}
这里填该出版物的摘要内容,支持Markdown格式——比如*强调文本*、有序/无序列表:
- 核心研究发现1
- 核心研究发现2
:::
:::

Authors. Year. ["Title".](https://stackoverflow.com/) *Journal*
::: {.collapse}
::: {.collapse-toggle}点击查看摘要
:::
::: {.collapse-content}
这是另一篇的摘要内容
:::
:::

#### 2023

### Work In Progress

方法2:Bootstrap折叠组件(自定义样式)

如果要调整按钮样式、卡片外观,直接用Quarto默认集成的Bootstrap组件写HTML:

---
title: "Research"
---

### Publications

------------------------------------------------------------------------

#### 2022

Authors. Year. ["Title".](https://stackoverflow.com/) *Journal*
<button class="btn btn-outline-secondary" type="button" data-bs-toggle="collapse" data-bs-target="#abstract1" aria-expanded="false" aria-controls="abstract1">
  展开摘要
</button>
<div class="collapse" id="abstract1">
  <div class="card card-body mt-2">
    这里放摘要内容,嵌套Markdown语法也生效:
    **研究结论**:通过xxx方法验证了xxx假设
  </div>
</div>

### Work In Progress

方法3:自定义短代码(批量复用)

如果有几十上百篇出版物,自定义短代码能减少重复代码:

  1. 在网站根目录新建_extensions/abstract/abstract.lua文件,贴入以下代码:
function Div(el)
  if el.classes:includes("abstract-block") then
    local id = el.attributes.id or "abstract-" .. math.random(1000)
    local toggle_text = el.attributes.toggle or "点击查看摘要"
    local content = el.content
    return pandoc.Div({
      pandoc.RawBlock("html", '<button class="btn btn-link" type="button" data-bs-toggle="collapse" data-bs-target="#' .. id .. '" aria-expanded="false" aria-controls="' .. id .. '">' .. toggle_text .. '</button>'),
      pandoc.RawBlock("html", '<div class="collapse" id="' .. id .. '"><div class="card card-body">'),
      content,
      pandoc.RawBlock("html", '</div></div>')
    })
  end
end
  1. 在你的.qmd文件里启用扩展并使用:
---
title: "Research"
extensions: [abstract]
---

### Publications

------------------------------------------------------------------------

#### 2022

Authors. Year. ["Title".](https://stackoverflow.com/) *Journal*
::: {.abstract-block toggle="展开摘要"}
这里是摘要内容
:::

### Work In Progress

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 13:43:18