Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Visual Editor silently drops empty attributed spans ([]{.class …}) on a Source↔Visual round-trip

未关闭
#1,133 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
70/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
markdown, typescript

调研方向

The issue is in the panmirror editor's representation of empty spans. Start by examining packages/editor/src/marks/span.ts to understand how spans are modeled as ProseMirror marks. Then look at packages/editor/src/pandoc/pandoc_to_prosemirror.ts for the reading logic and the corresponding writing logic. The fix likely involves creating a placeholder node or handling empty spans specially to preserve their attributes. Test by modifying the editor and verifying that empty attributed spans survive a source-visual-source round-trip.

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

描述

bug visual-editor
Bug description

Originally reported downstream

When a document contains an empty attributed span — []{.class key="val"} with no text between the brackets — the Visual Editor deletes it on the first Source → Visual → Source round-trip. A non-empty span ([text]{.class …}) round-trips correctly. The deletion is silent (no warning), so it is easy to lose content.

Steps to reproduce

Start with this Markdown in Source mode:

Before []{.comment remark="EMPTY SPAN TEST"} after.

Before [some words]{.comment remark="NONEMPTY SPAN TEST"} after.

Switch to Visual mode, then back to Source mode, without making any edit. Result:

Before after.

Before [some words]{.comment remark="NONEMPTY SPAN TEST"} after.

The standalone empty span is gone; the one wrapping text remains.

Actual behavior

The empty span (and its attributes) is removed entirely.

This is not Pandoc — it's the editor's document model

Round-tripping the same input through the Pandoc that Quarto bundles preserves both spans, so nothing in Pandoc/Quarto strips it:

printf 'Before []{.comment remark="x"} after.\n' | quarto pandoc -f markdown -t markdown
# -> Before []{.comment remark="x"} after.        (empty span preserved)

The loss happens in panmirror (the Visual Editor's ProseMirror layer). A span is modeled as a ProseMirror mark, not a node — see packages/editor/src/marks/span.ts: the Pandoc Span token is read as a mark applied to the span's children (getChildren), and written back by re-wrapping those children.

A ProseMirror mark can only exist on text. An empty span has no children, so:

  • on read, there is nothing for the mark to attach to → the mark (and its attributes) is dropped;
  • on write-back, there is no marked text → no Span token is emitted.

This is consistent with the reader, which guards text creation with if (!text) return in pandoc_to_prosemirror.ts, and with prosemirror-model itself, where schema.text("") throws RangeError: Empty text nodes are not allowed — so an empty span can never produce an anchor node.

A non-empty span has children to carry the mark, which is exactly why it round-trips fine.

Impact

Any extension relying on empty attributed spans loses that content silently whenever the author touches the Visual Editor. Because it is a consequence of the "span = mark" modeling, no extension-side setting can recover it — it needs handling in the editor.

Expected behavior

Empty attributed spans are valid Pandoc AST and should survive the round-trip unchanged, exactly like non-empty ones. They are used by real extensions (e.g. annotation/comment tooling) to attach metadata at a point in the text, so dropping them is data loss.

Could you reserve empty attributed spans across the round-trip — e.g. by representing an empty span as a small node/anchor rather than a mark with no content, so its attributes survive ? Even preserving it as a raw/verbatim inline would avoid the silent data loss.

Your environment

The root cause is at the editor-model level (panmirror), so it is not expected to be platform- or IDE-specific (RStudio and the VS Code Quarto visual editor share panmirror).

Initial poster (@gasperploj) environment :

  • Quarto: 1.9.38
  • RStudio: 2026.07.0 Build 139
  • OS: Windows 10

Also reproduced by myself via the bundled Pandoc for the AST checks above on macOS / Quarto 1.10.18

主要语言
TypeScript
星标
657
派生
64
平均合并
20 小时 53 分钟
30 天内合并 PR
46

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

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

quarto-dev/quarto 的其他 Issue

查看 quarto-dev/quarto 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

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