// Copyright 2012 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.package docimport ()// firstSentence returns the first sentence in s.// The sentence ends after the first period followed by space and// not preceded by exactly one uppercase letter.func firstSentence( string) string {var , , runefor , := range {if == '\n' || == '\r' || == '\t' { = ' ' }if == ' ' && == '.' && (!unicode.IsUpper() || unicode.IsUpper()) {return [:] }if == '。' || == '.' {return [:] } , , = , , }return}// Synopsis returns a cleaned version of the first sentence in text.//// Deprecated: New programs should use [Package.Synopsis] instead,// which handles links in text properly.func ( string) string {varPackagereturn .Synopsis()}// IllegalPrefixes is a list of lower-case prefixes that identify// a comment as not being a doc comment.// This helps to avoid misinterpreting the common mistake// of a copyright notice immediately before a package statement// as being a doc comment.varIllegalPrefixes = []string{"copyright","all rights","author",}// Synopsis returns a cleaned version of the first sentence in text.// That sentence ends after the first period followed by space and not// preceded by exactly one uppercase letter, or at the first paragraph break.// The result string has no \n, \r, or \t characters and uses only single// spaces between words. If text starts with any of the [IllegalPrefixes],// the result is the empty string.func ( *Package) ( string) string { = firstSentence() := strings.ToLower()for , := rangeIllegalPrefixes {ifstrings.HasPrefix(, ) {return"" } } := .Printer() .TextWidth = -1 := .Parser().Parse()iflen(.Content) == 0 {return"" }if , := .Content[0].(*comment.Paragraph); ! {return"" } .Content = .Content[:1] // might be blank lines, code blocks, etc in “first sentence”returnstrings.TrimSpace(string(.Text()))}
The pages are generated with Goldsv0.7.0-preview. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.