internal/godoc/dochtml/internal/render: use default comment parser
Use the comment.Parser returned by doc.Package.Parser.
Change-Id: I1507f1ab83abb5a0c1e311c3bdf8f76943c809de
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/413676
Reviewed-by: Jamal Carvalho <jamal@golang.org>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
diff --git a/internal/godoc/dochtml/internal/render/linkify.go b/internal/godoc/dochtml/internal/render/linkify.go
index d90073c..3dfc045 100644
--- a/internal/godoc/dochtml/internal/render/linkify.go
+++ b/internal/godoc/dochtml/internal/render/linkify.go
@@ -112,8 +112,7 @@
)
func (r *Renderer) formatDocHTML(text string, extractLinks bool) safe.HTML {
- p := comment.Parser{}
- doc := p.Parse(text)
+ doc := r.commentParser.Parse(text)
if extractLinks {
r.removeLinks(doc)
}
diff --git a/internal/godoc/dochtml/internal/render/linkify_test.go b/internal/godoc/dochtml/internal/render/linkify_test.go
index 8bd846c..f8eb67f 100644
--- a/internal/godoc/dochtml/internal/render/linkify_test.go
+++ b/internal/godoc/dochtml/internal/render/linkify_test.go
@@ -176,6 +176,18 @@
doc: "For more detail, run ``go help test'' and ``go help testflag''",
want: `<p>For more detail, run “go help test” and “go help testflag”` + "\n" + "</p>",
},
+ {
+ name: "symbol links",
+ doc: "Links to [Month] and [Time.After].",
+ want: `<p>Links to <a href="#Month">Month</a> and <a href="#Time.After">Time.After</a>.
+</p>`,
+ },
+ {
+ name: "package links",
+ doc: "Links to [time] and [github.com/a/b].",
+ want: `<p>Links to <a href="">time</a> and <a href="/github.com/a/b">github.com/a/b</a>.
+</p>`,
+ },
} {
t.Run(test.name, func(t *testing.T) {
extractLinks := test.extractLinks
diff --git a/internal/godoc/dochtml/internal/render/render.go b/internal/godoc/dochtml/internal/render/render.go
index ccabb98..f2a75cf 100644
--- a/internal/godoc/dochtml/internal/render/render.go
+++ b/internal/godoc/dochtml/internal/render/render.go
@@ -10,6 +10,7 @@
"context"
"go/ast"
"go/doc"
+ "go/doc/comment"
"go/token"
"regexp"
"strings"
@@ -32,6 +33,7 @@
docTmpl *template.Template
exampleTmpl *template.Template
links []Link // Links removed from package overview to be displayed elsewhere.
+ commentParser *comment.Parser
}
type Options struct {
@@ -110,6 +112,7 @@
docTmpl: docDataTmpl,
exampleTmpl: exampleTmpl,
ctx: ctx,
+ commentParser: pkg.Parser(),
}
}