From 6c7b223c2bfa700d9e1dc53d58c1c998493126e0 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Fri, 3 Jun 2022 09:18:57 -0400 Subject: [PATCH] =?utf8?q?go/doc/comment:=20do=20not=20turn=20```=20into?= =?utf8?q?=20=E2=80=9C`?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit ``` is Markdown, not Go doc comment, but some small fraction of users get confused. In a set of 55M Go doc comments drawn from the latest version of all public Go modules known to the module proxy in spring 2020, the current Go 1.19 gofmt reformats about 1.57M of them. Out of those 1.57M comments, 8k of them (about 0.5%) contain ```. Instead of rewriting ``` to “`, leave it alone. For #51082. Change-Id: I1c8c88aac7ef75ec03e1a396b84ffe711c46f941 Reviewed-on: https://go-review.googlesource.com/c/go/+/410359 Reviewed-by: Ian Lance Taylor TryBot-Result: Gopher Robot Run-TryBot: Russ Cox --- src/go/doc/comment/parse.go | 8 ++++++++ src/go/doc/comment/testdata/quote.txt | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/go/doc/comment/parse.go b/src/go/doc/comment/parse.go index 83b37c32c5..8a311ff817 100644 --- a/src/go/doc/comment/parse.go +++ b/src/go/doc/comment/parse.go @@ -840,6 +840,14 @@ func (d *parseDoc) parseText(out []Text, s string, autoLink bool) []Text { } switch { case strings.HasPrefix(t, "``"): + if len(t) >= 3 && t[2] == '`' { + // Do not convert `` inside ```, in case people are mistakenly writing Markdown. + i += 3 + for i < len(t) && t[i] == '`' { + i++ + } + break + } writeUntil(i) w.WriteRune('“') i += 2 diff --git a/src/go/doc/comment/testdata/quote.txt b/src/go/doc/comment/testdata/quote.txt index 799663af80..b64adae0b3 100644 --- a/src/go/doc/comment/testdata/quote.txt +++ b/src/go/doc/comment/testdata/quote.txt @@ -1,12 +1,15 @@ -- input -- Doubled single quotes like `` and '' turn into Unicode double quotes, but single quotes ` and ' do not. +Misplaced markdown fences ``` do not either. -- gofmt -- Doubled single quotes like “ and ” turn into Unicode double quotes, but single quotes ` and ' do not. +Misplaced markdown fences ``` do not either. -- text -- Doubled single quotes like “ and ” turn into Unicode double quotes, but single -quotes ` and ' do not. +quotes ` and ' do not. Misplaced markdown fences ``` do not either. -- html --

Doubled single quotes like “ and ” turn into Unicode double quotes, but single quotes ` and ' do not. +Misplaced markdown fences ``` do not either. -- 2.48.1