Skip to content

docs write --append --markdown: 3rd+ table in single call reorders trailing punctuation of preceding paragraph #607

@chrischall

Description

@chrischall

Summary

When gog docs write --append --markdown is given input containing three or more tables separated by paragraphs, the trailing punctuation of the paragraph immediately before the third (and any subsequent) table is reordered — moved to a separate paragraph after the corresponding table. The first two paragraph+table pairs render correctly.

Reported by my AI agent (Claude Code) while building MCP coverage on top of gogcli.

Repro

cat > /tmp/repro.md <<'MD'
Paragraph A ending in word one.

| h1 | h2 |
|----|----|
| a  | b  |

Paragraph B ending in word two.

| h1 | h2 |
|----|----|
| c  | d  |

Paragraph C ending in word three.

| h1 | h2 |
|----|----|
| e  | f  |
MD

DOC=$(gog docs create "MD bug repro" --json | jq -r '.file.id')
gog docs write "$DOC" --append --markdown --file=/tmp/repro.md
gog docs cat "$DOC" --json | jq -r '.text'

Expected

Three paragraphs each followed by a 2×2 table, with the trailing words intact (one., two., three.).

Actual

Paragraph A ending in word one.

h1	h2
a	b

Paragraph B ending in word two.
h1	h2
c	d

Paragraph C ending in word three        ← period missing
h1	h2
e	f
.                                       ← period appears as standalone paragraph

The period (or trailing 1–2 chars) of the third paragraph is moved to a standalone paragraph after the third table.

Build

v0.17.0 (aee7460 2026-05-15T18:10:07Z) (macOS, Homebrew install)

Notes

  • First two paragraph+table pairs are fine; the corruption only starts at the 3rd table.
  • Suggests an off-by-one or index-bookkeeping issue in the per-table insert loop — after the second table insert, the running insertion index for the next paragraph appears to be one char short of where the paragraph actually ends.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions