From f5e568eee09883f1e29582ba346c9369f1cb0ef0 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 26 Apr 2026 02:55:24 +0000 Subject: [PATCH] fix: preserve word boundaries between text and inline-formatted nodes extractPlainText was trimming each text node and inserting a synthetic space only between consecutive text nodes, causing adjacent emphasis/code spans to merge with the preceding word. Write text node values verbatim and trim once at the end instead. https://claude.ai/code/session_011KRAawZFT53ysP3vHjB54D --- parser.go | 9 ++------- testdata/golden/title_inline_formatting.json | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/parser.go b/parser.go index 47d2e4a..d6372dd 100644 --- a/parser.go +++ b/parser.go @@ -885,12 +885,7 @@ func extractPlainText(node ast.Node, source []byte) (string, error) { var buf bytes.Buffer for child := node.FirstChild(); child != nil; child = child.NextSibling() { if text, ok := child.(*ast.Text); ok { - if buf.Len() > 0 { - if _, err := buf.WriteRune(' '); err != nil { - return "", fmt.Errorf("buf.WriteRune: %w", err) - } - } - if _, err := buf.Write(bytes.TrimSpace(text.Value(source))); err != nil { + if _, err := buf.Write(text.Value(source)); err != nil { return "", fmt.Errorf("buf.Write: %w", err) } } else { @@ -901,7 +896,7 @@ func extractPlainText(node ast.Node, source []byte) (string, error) { buf.WriteString(childText) } } - return buf.String(), nil + return strings.TrimSpace(buf.String()), nil } // extractRawMarkdown extracts raw source for a block node, preserving markdown syntax. diff --git a/testdata/golden/title_inline_formatting.json b/testdata/golden/title_inline_formatting.json index 45ae2bb..2780597 100644 --- a/testdata/golden/title_inline_formatting.json +++ b/testdata/golden/title_inline_formatting.json @@ -1,5 +1,5 @@ { - "title": "Title withemphasis andcode", + "title": "Title with emphasis and code", "description": null, "yields": [], "tags": [],