Heading anchor links have no icon: AnchorJS is initialised with an empty `icon`

未关闭 适合新手
#1,419 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@cscheid 已经在做这个了。

开始于 2026年11月30日。

  • #1422 来自 @cscheid —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
rust
领域
frontend

调研方向

从 crates/quarto-core/src/transforms/anchor_sections.rs 中的 INIT_SCRIPT 入手,并将其 AnchorJS 设置与 issue 中描述的 Quarto 1 行为进行比较。报告的输出显示生成的图标为空;渲染所提供的网站复现示例,并检查标题链接是否显示 AnchorJS 的图标,以此验证修复。

由索引模型根据 Issue 内容生成。

描述

This issue was drafted with Claude. The output shown comes from running each repro.

Bug description

Heading anchor links have no icon. q2 adds the .anchorjs-link to each heading, and the link
appears on hover, but it is empty, so readers cannot see or click it.

q2 initialises AnchorJS with icon: ''. Quarto 1 passes a one-character string, U+E9CB, a
private-use glyph that AnchorJS draws with its own anchorjs-icons font. When icon is that
glyph, AnchorJS also sets font: 1em/1 anchorjs-icons on the link. With an empty string it
draws content: attr(data-anchorjs-icon), which is empty.

The cause looks like an invisible character that was lost when the init was ported. In Quarto
1's quarto-html-after-body.ejs (line 75), the line reads
const icon = "<%= anchors === true ? '' : anchors %>";, but the quotes hold U+E9CB:

$ sed -n 75p share/formats/html/templates/quarto-html-after-body.ejs | xxd | sed -n 3p
00000020: 3d20 7472 7565 203f 2027 eea7 8b27 203a  = true ? '...' :

In q2, INIT_SCRIPT in crates/quarto-core/src/transforms/anchor_sections.rs (at 9bf91d18c)
has a truly empty string, and its doc comment says "with icon empty, which is what Q1 renders
for anchors === true":

$ sed -n 126p crates/quarto-core/src/transforms/anchor_sections.rs | xxd
00000000: 2020 2020 6963 6f6e 3a20 2727 5c6e 5c0a      icon: ''\n\.
Steps to reproduce
mkdir anchor-icon && cd anchor-icon
printf 'project:\n  type: website\nwebsite:\n  title: Demo\n' > _quarto.yml
printf -- '---\ntitle: Anchors\n---\n\n## A heading\n\nText.\n' > index.qmd
q2 render
grep -o "icon: [^,}]*" _site/index.html | xxd

Then open _site/index.html and hover over "A heading". There is a link target after the heading
text, but nothing is drawn.

Actual behavior

With q2 0.47.0 and with 0.45.0-nightly.20261112:

00000000: 6963 6f6e 3a20 2727 0a                   icon: ''.
Expected behavior

Quarto 1.11.9 with the same files (quarto render, then
grep -o 'const icon = "[^"]*"' _site/index.html | xxd):

00000000: 636f 6e73 7420 6963 6f6e 203d 2022 eea7  const icon = "..
00000010: 8b22 0a                                  .".

Hovering over the heading shows AnchorJS's link icon.

A possible fix is to write the glyph as an escape in INIT_SCRIPT (icon: '', which is
'\\ue9cb' inside the Rust string), so it cannot be lost again.

Workaround
.anchorjs-link[data-anchorjs-icon=""]::after {
  content: "\e9cb";
  font: 1em/1 anchorjs-icons;
}

AnchorJS registers the anchorjs-icons font whenever it adds links, so this draws the same icon
as Quarto 1, and it stops applying once the icon is set.

Environment
  • q2 0.47.0 (latest release) and 0.45.0-nightly.20261112, macOS arm64
  • Quarto 1.11.9 for the comparison
主要语言
Rust
星标
316
派生
23
平均合并
11 小时 49 分钟
30 天内合并 PR
245

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

quarto-dev/q2 的其他 Issue

查看 quarto-dev/q2 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。