mirror of https://github.com/golang/go.git
go/doc/comment: do not turn ``` into “`
``` 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 <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Russ Cox <rsc@golang.org>
This commit is contained in:
parent
ce757e94e0
commit
6c7b223c2b
|
|
@ -840,6 +840,14 @@ func (d *parseDoc) parseText(out []Text, s string, autoLink bool) []Text {
|
||||||
}
|
}
|
||||||
switch {
|
switch {
|
||||||
case strings.HasPrefix(t, "``"):
|
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)
|
writeUntil(i)
|
||||||
w.WriteRune('“')
|
w.WriteRune('“')
|
||||||
i += 2
|
i += 2
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,15 @@
|
||||||
-- input --
|
-- input --
|
||||||
Doubled single quotes like `` and '' turn into Unicode double quotes,
|
Doubled single quotes like `` and '' turn into Unicode double quotes,
|
||||||
but single quotes ` and ' do not.
|
but single quotes ` and ' do not.
|
||||||
|
Misplaced markdown fences ``` do not either.
|
||||||
-- gofmt --
|
-- gofmt --
|
||||||
Doubled single quotes like “ and ” turn into Unicode double quotes,
|
Doubled single quotes like “ and ” turn into Unicode double quotes,
|
||||||
but single quotes ` and ' do not.
|
but single quotes ` and ' do not.
|
||||||
|
Misplaced markdown fences ``` do not either.
|
||||||
-- text --
|
-- text --
|
||||||
Doubled single quotes like “ and ” turn into Unicode double quotes, but single
|
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 --
|
-- html --
|
||||||
<p>Doubled single quotes like “ and ” turn into Unicode double quotes,
|
<p>Doubled single quotes like “ and ” turn into Unicode double quotes,
|
||||||
but single quotes ` and ' do not.
|
but single quotes ` and ' do not.
|
||||||
|
Misplaced markdown fences ``` do not either.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue