Skip to content

Visual Editor strips cross-reference ID from inline table caption #977

Open

Description

@mcanouil

Bug description

Switching a .qmd from source to the Visual Editor (and back) strips the cross-reference ID from a table caption written in the inline form : Caption {#tbl-one}.
After the round-trip the caption becomes : Caption and @tbl-one no longer resolves.

The equivalent div form ::: {#tbl-two} ... ::: is preserved, so the bug is specific to the inline caption attribute syntax.

Originally reported in quarto-dev/quarto-cli#14514.

Steps to reproduce

  1. Create issue.qmd:

    ---
    title: About
    format: html
    ---
    
    @tbl-one and @tbl-two
    
    | A | B | C |
    |---|---|---|
    | 1 | 2 | 3 |
    
    : Caption {#tbl-one}
    
    ::: {#tbl-two}
    
    | A | B | C |
    |---|---|---|
    | 1 | 2 | 3 |
    
    Caption
    
    :::
  2. Open in the Visual Editor, make any edit (or just toggle and save).

  3. Switch back to source.

Actual behavior

The {#tbl-one} attribute is removed from the caption:

| A   | B   | C   |
|-----|-----|-----|
| 1   | 2   | 3   |

: Caption

@tbl-one renders as ?@tbl-one and the cross-reference is broken.
The {#tbl-two} div form survives the round-trip unchanged.

Expected behavior

The Visual Editor should preserve {#tbl-one} on the table caption across round-trips, matching its behaviour for div-wrapped tables.

Your environment

Activity

  1. juliasilge commented on May 14, 2026

    @juliasilge
    Collaborator

    We've also got this tracked at posit-dev/positron#13204.

  2. added
    bug
    on May 14, 2026
  3. mcanouil commented on May 14, 2026

    @mcanouil
    ContributorAuthor

    Workaround and in general in Quarto, the div syntax is the most consistent one and probably the syntax that should be recommended even if a bit more verbose.

  4. cscheid commented on May 14, 2026

    @cscheid
    Member

    I wouldn't change any recommendations while we have the Quarto 2 work in flight. This sort of thing will be improved (and I continually thank you all for the patience...)

  5. gtritchie commented on Jul 9, 2026

    @gtritchie
    Collaborator

    I investigated this from the RStudio side (rstudio/rstudio#17890 is the same bug -- regressed between RStudio 2026.01.2+418 and 2026.04.0+526; rstudio/rstudio#18170 has been closed as a duplicate of it) and found the root cause.

    Root cause

    The trigger is the pandoc that ships with Quarto 1.9 (pandoc 3.6.3 → 3.8.3). Pandoc 3.8.2 introduced a new table_attributes extension (jgm/pandoc#10884), enabled by default for markdown. The markdown reader now parses : Caption {#tbl-one} into the Table AST node's Attr instead of leaving {#tbl-one} as literal caption text:

    $ pandoc-3.6.3 -f markdown -t json repro.md   # table block:
    attr: ["", [], []]        caption: ... Str "Caption", Space, Str "{#tbl-one}"
    
    $ pandoc-3.8.3 -f markdown -t json repro.md   # table block:
    attr: ["tbl-one", [], []] caption: ... Str "Caption"
    

    The visual editor has never round-tripped Table Attr: in packages/editor/src/nodes/table/table-pandoc.ts, readPandocTable ignores token index 0 (// const kTableAttr = 0; is commented out) and writePandocTableContainer always writes an empty attr. Before pandoc 3.8.2 the id survived because it was just caption text; now it arrives in a slot the editor discards, so it's dropped on the source → visual → source round trip.

    This explains why:

    • the div form ::: {#tbl-two} is unaffected (divs round-trip their attr),
    • it regressed without any table-related change in this repo (the panmirror diff between the RStudio 2026.01 and 2026.04 release branches has no table changes),
    • it reproduces in RStudio 2026.04+ (first release bundling Quarto 1.9) and in VS Code/Positron with Quarto ≥ 1.9.

    Note it's not just crossref ids — all table attributes are dropped ({.striped}, tbl-colwidths="...", etc.).

    Suggested fix

    Two options that restore the previous behavior:

    1. Re-materialize the attr as caption text on read (minimal, no version gating): in readPandocTable, read the attr (pandocAttrReadAST(tok, 0) already exists) and, when non-empty, append its textual form ({#tbl-one}) to the caption inlines. The writer can stay as is: pandoc 3.8.3 writes literal {#tbl-...} caption text back unescaped even with table_attributes enabled (verified), and re-reading parses it back into Attr, so the round trip is stable. This exactly restores the pre-3.8.2 UX where the id is visible/editable in the caption.

    2. Disable the extension on read: add table_attributes to the disabled list in pandoc_converter.ts toProsemirror (the adjustedFormat(..., ['smart']) call). Caveat: pandoc < 3.8.2 errors on unknown extension names (The extension table_attributes is not supported for markdown.), so this needs a pandoc-version gate (there's an existing semver-check pattern in fromProsemirror).

    Longer term, properly round-tripping Table Attr as a node attr (with attr-editing UI) would also preserve classes/key-values, but the options above fix the regression without new UI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugvisual-editorvscode

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions