// addSymbolLinks looks for text like [Buffer] and // [math.Max] and replaces them with links to standard library // symbols and packages. // It uses the given default package for links without a package. func addSymbolLinks(doc *md.Document, defaultPackage string) { … } func addSymbolLinksBlocks(bs []md.Block, defaultPackage string) { … } func addSymbolLinksBlock(b md.Block, defaultPackage string) { … } // addSymbolLinksInlines looks for symbol links in the slice of inline markdown // elements. It returns a new slice of inline elements with links added. func addSymbolLinksInlines(ins []md.Inline, defaultPackage string) []md.Inline { … } // splitAtBrackets rewrites ins so that every '[' and ']' is the only character // of its Plain. // For example, the element // // [Plain("the [Buffer] is")] // // is rewritten to // // [Plain("the "), Plain("["), Plain("Buffer"), Plain("]"), Plain(" is")] // // This transformation simplifies looking for symbol links. func splitAtBrackets(ins []md.Inline) []md.Inline { … } // symbolLinkText returns the text of a possible symbol link. // It is given a slice of Inline elements and an index into the slice. // If the index refers to a sequence of elements // // [Plain("["), Plain_or_Code(text), Plain("]")] // // and the brackets are adjacent to the right kind of runes for a link, then // symbolLinkText returns the text of the middle element. // Otherwise it returns the empty string. func symbolLinkText(i int, ins []md.Inline) string { … } // symbolLink converts s into a Link and returns it and true, or nil and false if // s is not a valid link or is surrounded by runes that disqualify it from being // converted to a link. // // The argument s is the text between '[' and ']'. func symbolLink(s, defaultPackage string) (md.Inline, bool) { … } // isLinkAdjacentRune reports whether r can be adjacent to a symbol link. // The logic is the same as the go/doc/comment package. func isLinkAdjacentRune(r rune) bool { … } // splitRef splits s into a package and possibly a symbol. // Examples: // // splitRef("math.Max") => ("math", "Max", true) // splitRef("bytes.Buffer.String") => ("bytes", "Buffer.String", true) // splitRef("math") => ("math", "", true) func splitRef(s string) (pkg, name string, ok bool) { … } // If text is of the form before.Name, where Name is a capitalized Go identifier, // then splitDocName returns before, name, true. // Otherwise it returns text, "", false. func splitDocName(text string) (before, name string, foundDot bool) { … } // isName reports whether s is a capitalized Go identifier (like Name). func isName(s string) bool { … } // ident checks whether s begins with a Go identifier. // If so, it returns the identifier, which is a prefix of s, and ok == true. // Otherwise it returns "", false. // The caller should skip over the first len(id) bytes of s // before further processing. func ident(s string) (id string, ok bool) { … } // isIdentASCII reports whether c is an ASCII identifier byte. func isIdentASCII(c byte) bool { … }