Linkify RFCs in more places in the docs. Also don't linkify pipe words in the table of contents. Those are already inside a link. Change-Id: Ib984e914bcfe7a8e0216a0553b92100fd034bf36 Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/51605 Reviewed-by: Adam Langley <agl@google.com>
diff --git a/util/doc.go b/util/doc.go index a38e078..651998e 100644 --- a/util/doc.go +++ b/util/doc.go
@@ -503,7 +503,7 @@ // markupPipeWords converts |s| into an HTML string, safe to be included outside // a tag, while also marking up words surrounded by |. -func markupPipeWords(allDecls map[string]string, s string) template.HTML { +func markupPipeWords(allDecls map[string]string, s string, linkDecls bool) template.HTML { // It is safe to look for '|' in the HTML-escaped version of |s| // below. The escaped version cannot include '|' instead tags because // there are no tags by construction. @@ -524,12 +524,10 @@ if i > 0 && (j == -1 || j > i) { ret += "<tt>" anchor, isLink := allDecls[s[:i]] - if isLink { - ret += fmt.Sprintf("<a href=\"%s\">", template.HTMLEscapeString(anchor)) - } - ret += s[:i] - if isLink { - ret += "</a>" + if linkDecls && isLink { + ret += fmt.Sprintf("<a href=\"%s\">%s</a>", template.HTMLEscapeString(anchor), s[:i]) + } else { + ret += s[:i] } ret += "</tt>" s = s[i+1:] @@ -602,11 +600,12 @@ headerTmpl := template.New("headerTmpl") headerTmpl.Funcs(template.FuncMap{ - "firstSentence": firstSentence, - "markupPipeWords": func(s string) template.HTML { return markupPipeWords(allDecls, s) }, - "markupFirstWord": markupFirstWord, - "markupRFC": markupRFC, - "newlinesToBR": newlinesToBR, + "firstSentence": firstSentence, + "markupPipeWords": func(s string) template.HTML { return markupPipeWords(allDecls, s, true /* linkDecls */) }, + "markupPipeWordsNoLink": func(s string) template.HTML { return markupPipeWords(allDecls, s, false /* linkDecls */) }, + "markupFirstWord": markupFirstWord, + "markupRFC": markupRFC, + "newlinesToBR": newlinesToBR, }) headerTmpl, err := headerTmpl.Parse(`<!DOCTYPE html> <html> @@ -623,12 +622,12 @@ <a href="headers.html">All headers</a> </div> - {{range .Preamble}}<p>{{. | markupPipeWords}}</p>{{end}} + {{range .Preamble}}<p>{{. | markupPipeWords | markupRFC}}</p>{{end}} <ol> {{range .Sections}} {{if not .IsPrivate}} - {{if .Anchor}}<li class="header"><a href="#{{.Anchor}}">{{.Preamble | firstSentence | markupPipeWords}}</a></li>{{end}} + {{if .Anchor}}<li class="header"><a href="#{{.Anchor}}">{{.Preamble | firstSentence | markupPipeWordsNoLink}}</a></li>{{end}} {{range .Decls}} {{if .Anchor}}<li><a href="#{{.Anchor}}"><tt>{{.Name}}</tt></a></li>{{end}} {{end}} @@ -641,7 +640,7 @@ <div class="section" {{if .Anchor}}id="{{.Anchor}}"{{end}}> {{if .Preamble}} <div class="sectionpreamble"> - {{range .Preamble}}<p>{{. | markupPipeWords}}</p>{{end}} + {{range .Preamble}}<p>{{. | markupPipeWords | markupRFC}}</p>{{end}} </div> {{end}}