Skip to content

Commit 58fe96e

Browse files
committed
fix(docs): preserve markdown paragraph breaks in tabs
1 parent 6bd333a commit 58fe96e

5 files changed

Lines changed: 20 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Gmail: clarify that `gmail drafts delete` permanently deletes drafts and cannot be recovered. (#656, #659) — thanks @chrischall.
99
- Sheets: add `--inherit-from-before` to `sheets insert` so callers can choose whether inserted rows/columns inherit formatting from the preceding or following neighbor. (#655, #658) — thanks @chrischall.
1010
- Auth: update stored OAuth scope metadata from observed granted scopes during refresh so `auth list` reflects newly usable services. (#649)
11+
- Docs: preserve paragraph-separating blank lines when replacing a single tab from Markdown. (#644)
1112
- Docs: update the bundled `gog` agent skill to preserve broad user OAuth scopes during reauth and rely on command guards for scoped execution.
1213

1314
## 0.19.0 - 2026-05-22

internal/cmd/docs_markdown.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ func ParseMarkdown(text string) []MarkdownElement {
106106

107107
// Empty line
108108
if strings.TrimSpace(line) == "" {
109+
if len(elements) > 0 && elements[len(elements)-1].Type != MDEmptyLine {
110+
elements = append(elements, MarkdownElement{Type: MDEmptyLine})
111+
}
109112
continue
110113
}
111114

@@ -205,6 +208,10 @@ func ParseMarkdown(text string) []MarkdownElement {
205208
})
206209
}
207210

211+
if len(elements) > 0 && elements[len(elements)-1].Type == MDEmptyLine {
212+
elements = elements[:len(elements)-1]
213+
}
214+
208215
return elements
209216
}
210217

internal/cmd/docs_markdown_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ func TestParseMarkdown(t *testing.T) {
4646
{
4747
name: "mixed content",
4848
input: "# Title\n\nParagraph here\n\n- List item",
49-
expected: []MarkdownElementType{MDHeading1, MDParagraph, MDListItem},
49+
expected: []MarkdownElementType{MDHeading1, MDEmptyLine, MDParagraph, MDEmptyLine, MDListItem},
50+
},
51+
{
52+
name: "consecutive blank lines collapse",
53+
input: "Paragraph A\n\n\nParagraph B\n",
54+
expected: []MarkdownElementType{MDParagraph, MDEmptyLine, MDParagraph},
5055
},
5156
}
5257

internal/cmd/docs_write_markdown_tab_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ func TestDocsWrite_MarkdownReplaceWithTab(t *testing.T) {
101101
if loc.TabId != "t.second" || loc.Index != 1 {
102102
t.Fatalf("insert location = %+v, want {TabId:t.second Index:1}", loc)
103103
}
104-
if got := insertReqs[0].InsertText.Text; got != "Title\nbold\n" {
105-
t.Fatalf("inserted text = %q, want %q", got, "Title\nbold\n")
104+
if got := insertReqs[0].InsertText.Text; got != "Title\n\nbold\n" {
105+
t.Fatalf("inserted text = %q, want %q", got, "Title\n\nbold\n")
106106
}
107107
for i, req := range insertReqs[1:] {
108108
var r *docs.Range

internal/cmd/docs_write_markdown_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ func TestDocsWrite_MarkdownAppendUsesDocsFormatting(t *testing.T) {
500500
if reqs[0].InsertText == nil {
501501
t.Fatalf("expected first request to insert text, got %#v", reqs[0])
502502
}
503-
if got := reqs[0].InsertText; got.Location.Index != 9 || got.Text != "\nTitle\nbold\n" {
503+
if got := reqs[0].InsertText; got.Location.Index != 9 || got.Text != "\nTitle\n\nbold\n" {
504504
t.Fatalf("unexpected markdown insert: %#v", got)
505505
}
506506
if reqs[1].UpdateParagraphStyle == nil {
@@ -512,7 +512,7 @@ func TestDocsWrite_MarkdownAppendUsesDocsFormatting(t *testing.T) {
512512
if reqs[2].UpdateTextStyle == nil {
513513
t.Fatalf("expected bold text style request, got %#v", reqs[2])
514514
}
515-
if got := reqs[2].UpdateTextStyle.Range; got.StartIndex != 16 || got.EndIndex != 20 {
515+
if got := reqs[2].UpdateTextStyle.Range; got.StartIndex != 17 || got.EndIndex != 21 {
516516
t.Fatalf("unexpected bold range: %#v", got)
517517
}
518518
}
@@ -569,13 +569,13 @@ func TestDocsWrite_MarkdownAppendStartsStyledBlocksOnFreshParagraph(t *testing.T
569569
if len(reqs) != 4 {
570570
t.Fatalf("expected insert, bullet, code font, and code shading requests, got %#v", reqs)
571571
}
572-
if got := reqs[0].InsertText; got == nil || got.Location.Index != 9 || got.Text != "\nItem\nline 1"+docsSoftLineBreak+"line 2\n" {
572+
if got := reqs[0].InsertText; got == nil || got.Location.Index != 9 || got.Text != "\nItem\n\nline 1"+docsSoftLineBreak+"line 2\n" {
573573
t.Fatalf("unexpected markdown insert: %#v", got)
574574
}
575575
if got := reqs[1].CreateParagraphBullets; got == nil || got.Range.StartIndex != 10 || got.Range.EndIndex != 15 {
576576
t.Fatalf("unexpected bullet request: %#v", got)
577577
}
578-
if got := reqs[3].UpdateParagraphStyle; got == nil || got.Range.StartIndex != 15 || got.Range.EndIndex != 29 {
578+
if got := reqs[3].UpdateParagraphStyle; got == nil || got.Range.StartIndex != 16 || got.Range.EndIndex != 30 {
579579
t.Fatalf("unexpected code shading request: %#v", got)
580580
}
581581
}

0 commit comments

Comments
 (0)