Commit 2bba4454b5 for golang

commit 2bba4454b56686943d3415bc9acec1fe6e4d7c83
Author: joyhsia <huanxiao210330@gmail.com>
Date:   Fri Dec 4 05:55:04 2026 +0000

    go/doc/comment: preserve arbitrary list numbers in Markdown

    Markdown renderers turn the labels 10, 20, 30 into 10, 11, 12.
    Preserve nonconsecutive and noncanonical labels by writing them as
    escaped text in a bulleted list. Continue using native ordered lists
    when Markdown can display their numbers unchanged.

    Extend the list fixtures to cover the reported example, repeated and
    descending labels, leading zeroes, and the nine-digit marker limit.
    The existing paragraph and inline formatting is retained.

    Fixes #83554

    Change-Id: I43a1b26751a86e54acf22198a55ae802294939a7
    GitHub-Last-Rev: ebc19c365be5f940bef0ca8fb21b6c610e7a06c1
    GitHub-Pull-Request: golang/go#83665
    Reviewed-on: https://go-review.googlesource.com/c/go/+/869042
    LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
    Reviewed-by: Alan Donovan <adonovan@google.com>
    Auto-Submit: Alan Donovan <adonovan@google.com>
    Reviewed-by: David Chase <drchase@google.com>

diff --git a/src/go/doc/comment/markdown.go b/src/go/doc/comment/markdown.go
index d8550f2e39..ea436d265d 100644
--- a/src/go/doc/comment/markdown.go
+++ b/src/go/doc/comment/markdown.go
@@ -68,17 +68,31 @@ func (p *mdPrinter) block(out *bytes.Buffer, x Block) {
 		}

 	case *List:
+		// Markdown numbers ordered lists consecutively and limits markers to
+		// nine digits. Use literal labels when that would change the numbering.
+		literal := false
+		for i, item := range x.Items {
+			n := item.Number
+			if n != "" && (len(n) > 9 || len(n) > 1 && n[0] == '0' || i > 0 && n != inc(x.Items[i-1].Number)) {
+				literal = true
+				break
+			}
+		}
 		loose := x.BlankBetween()
 		for i, item := range x.Items {
 			if i > 0 && loose {
 				out.WriteString("\n")
 			}
-			if n := item.Number; n != "" {
+			if n := item.Number; n != "" && !literal {
 				out.WriteString(" ")
 				out.WriteString(n)
 				out.WriteString(". ")
 			} else {
 				out.WriteString("  - ") // SP SP - SP
+				if literal {
+					out.WriteString(item.Number)
+					out.WriteString("\\. ")
+				}
 			}
 			for i, blk := range item.Content {
 				const fourSpace = "    "
diff --git a/src/go/doc/comment/testdata/list11.txt b/src/go/doc/comment/testdata/list11.txt
new file mode 100644
index 0000000000..5f9e83c7b1
--- /dev/null
+++ b/src/go/doc/comment/testdata/list11.txt
@@ -0,0 +1,84 @@
+-- input --
+Skipped numbers.
+ 10. FOR I = 1 TO 10 STEP 1
+ 20. PRINT "HELLO"
+ 30. NEXT I
+
+Descending numbers.
+ 3. Three
+ 2. Two
+ 1. One
+
+Leading zeroes.
+ 01. One
+ 02. Two
+
+Sequential numbers.
+ 10. Ten
+ 11. Eleven
+ 12. Twelve
+
+Zero-based numbers.
+ 0. Zero
+ 1. One
+
+Nine-digit numbers.
+ 999999998. First
+ 999999999. Second
+
+Ten-digit numbers.
+ 999999999. First
+ 1000000000. Second
+
+Multiple paragraphs.
+ 10. First paragraph with italicword.
+
+     Second paragraph.
+ 20. Another item.
+
+-- markdown --
+Skipped numbers.
+
+  - 10\. FOR I = 1 TO 10 STEP 1
+  - 20\. PRINT "HELLO"
+  - 30\. NEXT I
+
+Descending numbers.
+
+  - 3\. Three
+  - 2\. Two
+  - 1\. One
+
+Leading zeroes.
+
+  - 01\. One
+  - 02\. Two
+
+Sequential numbers.
+
+ 10. Ten
+ 11. Eleven
+ 12. Twelve
+
+Zero-based numbers.
+
+ 0. Zero
+ 1. One
+
+Nine-digit numbers.
+
+ 999999998. First
+ 999999999. Second
+
+Ten-digit numbers.
+
+  - 999999999\. First
+  - 1000000000\. Second
+
+Multiple paragraphs.
+
+  - 10\. First paragraph with *italicword*.
+
+    Second paragraph.
+
+  - 20\. Another item.
diff --git a/src/go/doc/comment/testdata/list2.txt b/src/go/doc/comment/testdata/list2.txt
index c390b3d59a..cf00e4da65 100644
--- a/src/go/doc/comment/testdata/list2.txt
+++ b/src/go/doc/comment/testdata/list2.txt
@@ -34,14 +34,14 @@ Text.
 -- markdown --
 Text.

- 1. Uno
- 2. Dos
- 3. Tres
- 5. Cinco
- 7. Siete
- 11. Once
- 12. Doce
- 13. Trece.
+  - 1\. Uno
+  - 2\. Dos
+  - 3\. Tres
+  - 5\. Cinco
+  - 7\. Siete
+  - 11\. Once
+  - 12\. Doce
+  - 13\. Trece.

 -- html --
 <p>Text.
diff --git a/src/go/doc/comment/testdata/list3.txt b/src/go/doc/comment/testdata/list3.txt
index d7d345d2d3..46c9a793a1 100644
--- a/src/go/doc/comment/testdata/list3.txt
+++ b/src/go/doc/comment/testdata/list3.txt
@@ -17,10 +17,10 @@ Text.
 -- markdown --
 Text.

- 1. Uno
- 1. Dos
- 1. Tres
- 1. Quatro
+  - 1\. Uno
+  - 1\. Dos
+  - 1\. Tres
+  - 1\. Quatro

 -- html --
 <p>Text.
diff --git a/src/go/doc/comment/testdata/list5.txt b/src/go/doc/comment/testdata/list5.txt
index a5128e5b7c..c11302b799 100644
--- a/src/go/doc/comment/testdata/list5.txt
+++ b/src/go/doc/comment/testdata/list5.txt
@@ -25,10 +25,10 @@ Text.
 -- markdown --
 Text.

- 1. One
- 999999999999999999999. Big
- 1000000000000000000000. Bigger
- 1000000000000000000001. Biggest
+  - 1\. One
+  - 999999999999999999999\. Big
+  - 1000000000000000000000\. Bigger
+  - 1000000000000000000001\. Biggest

 -- html --
 <p>Text.