ToMarkdown parses the godoc comment text and writes a Markdown rendering to w suitable for a repository README.md: top-level sections become ## headings without per-heading anchor IDs, and [Symbol] doc links resolve to pkg.go.dev, including for symbols in the current package (which the default print
(w io.Writer, text string)
| 53 | // including for symbols in the current package (which the default printer would |
| 54 | // otherwise emit as bare #Name fragments with no backing anchor). |
| 55 | func (pkg *Package) ToMarkdown(w io.Writer, text string) { |
| 56 | d := pkg.doc.Parser().Parse(text) |
| 57 | pr := pkg.doc.Printer() |
| 58 | pr.HeadingLevel = 2 |
| 59 | pr.HeadingID = func(*comment.Heading) string { return "" } |
| 60 | pr.DocLinkBaseURL = "https://pkg.go.dev" |
| 61 | pr.DocLinkURL = func(link *comment.DocLink) string { |
| 62 | importPath := link.ImportPath |
| 63 | if importPath == "" { |
| 64 | importPath = pkg.doc.ImportPath |
| 65 | } |
| 66 | name := link.Name |
| 67 | if link.Recv != "" { |
| 68 | name = link.Recv + "." + name |
| 69 | } |
| 70 | return "https://pkg.go.dev/" + importPath + "#" + name |
| 71 | } |
| 72 | w.Write(pr.Markdown(d)) |
| 73 | } |
| 74 | |
| 75 | // pkgBuffer is a wrapper for bytes.Buffer that prints a package clause the |
| 76 | // first time Write is called. |
no test coverage detected