Skip to content

Inline citation attachment can break block Markdown and hide verified citations #123

Description

@cpsievert

Problem

PR #107 originally preserved the whitespace before each verified citation aside.

Commit f0a46de added logic that removes this whitespace. The scanner now places
the aside directly after the preceding visible text.

This behavior can break Markdown blocks. A verified citation can disappear from
the user interface, while Commons still records the answer as Cited.

Regression

The last PR commit before the later changes was 5b497232. For an answer that
ends with a fenced code block, that version produced this structure:

```r
1 + 1
```

<shiny-aside ...>

After f0a46de, the scanner produces this structure:

```r
1 + 1
```<shiny-aside ...>

The <shiny-aside> text becomes part of the code block because the closing
fence is no longer valid Markdown.

The merged state of PR #107, at 426236d, contains this behavior.

User impact

I reproduced these results in a real shinychat browser:

  • A plain paragraph showed one citation pill.
  • A fenced code block showed no citation pill. The aside markup appeared inside
    the code block.
  • A Markdown table showed no citation pill. The citation quote appeared as a
    separate blockquote.

The server still records the citation decision as accepted. stream_async()
therefore derives provenance tag B.

Tag B does not get a separate provenance aside. Its citation is expected to
provide the visible trust indicator. The user can therefore see no citation
indicator, while the trace records the answer as Cited.

This breaks the contract in PR #107. The displayed provenance and the recorded
provenance no longer represent the same result.

Root cause

R/citation-scan.R now keeps trailing whitespace in
pending_whitespace. emit_attachment() removes that whitespace when prior
visible text exists:

if (has_attachment_target) {
  pending_whitespace <<- ""
}

The scanner does not determine whether the preceding text ends with block
Markdown. It always joins the aside to that text.

Test gap

The scanner test added with f0a46de uses a plain sentence. It asserts that the
aside immediately follows the sentence.

The browser fixture also uses paragraph content. It does not cover answers that
end with:

  • A fenced code block
  • A Markdown table
  • Other block Markdown that requires a line boundary

Expected behavior

Citation projection must preserve the structure of preceding Markdown blocks.
A verified citation must remain visible when it causes provenance tag B.

Add browser regression tests for fenced code blocks and tables. These tests
must also make sure that an accepted citation produces visible citation UI.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions