mirror of
https://github.com/golang/go
synced 2024-11-18 07:34:53 -07:00
present: allow markup inside punctuation connected to other text
This allows markup bracketed by punctuation even when the punctuation has text on the other side, like in: - Markup—_especially_italic_text_—can easily be overused. - We want to increase `go`vet`'s usage. Change-Id: I0c6ca790f23f705d8c8ba8a225c0280b916ebb6c Reviewed-on: https://go-review.googlesource.com/33662 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Rob Pike <r@golang.org>
This commit is contained in:
parent
e5f9a3deee
commit
e04df2157a
@ -77,14 +77,22 @@ Fonts:
|
||||
Within the input for plain text or lists, text bracketed by font
|
||||
markers will be presented in italic, bold, or program font.
|
||||
Marker characters are _ (italic), * (bold) and ` (program font).
|
||||
Unmatched markers appear as plain text.
|
||||
Within marked text, a single marker character becomes a space
|
||||
and a doubled single marker quotes the marker character.
|
||||
An opening marker must be preceded by a space or punctuation
|
||||
character or else be at start of a line; similarly, a closing
|
||||
marker must be followed by a space or punctuation character or
|
||||
else be at the end of a line. Unmatched markers appear as plain text.
|
||||
There must be no spaces between markers. Within marked text,
|
||||
a single marker character becomes a space and a doubled single
|
||||
marker quotes the marker character.
|
||||
|
||||
at the beginning of a line or
|
||||
else be preceded by a space or punctuation; similarly a closing
|
||||
marker must be at the end of the lineo
|
||||
|
||||
_italic_
|
||||
*bold*
|
||||
`program`
|
||||
_this_is_all_italic_
|
||||
Markup—_especially_italic_text_—can easily be overused.
|
||||
_Why_use_scoped__ptr_? Use plain ***ptr* instead.
|
||||
|
||||
Inline links:
|
||||
|
@ -52,16 +52,16 @@ Word:
|
||||
words[w] = link
|
||||
continue Word
|
||||
}
|
||||
const punctuation = `.,;:()!?—–'"`
|
||||
const marker = "_*`"
|
||||
// Initial punctuation is OK but must be peeled off.
|
||||
first := strings.IndexAny(word, marker)
|
||||
if first == -1 {
|
||||
continue Word
|
||||
}
|
||||
// Is the marker prefixed only by punctuation?
|
||||
for _, r := range word[:first] {
|
||||
if !strings.ContainsRune(punctuation, r) {
|
||||
// Opening marker must be at the beginning of the token or else preceded by punctuation.
|
||||
if first != 0 {
|
||||
r, _ := utf8.DecodeLastRuneInString(word[:first])
|
||||
if !unicode.IsPunct(r) {
|
||||
continue Word
|
||||
}
|
||||
}
|
||||
@ -81,17 +81,18 @@ Word:
|
||||
open += "<code>"
|
||||
close = "</code>"
|
||||
}
|
||||
// Terminal punctuation is OK but must be peeled off.
|
||||
// Closing marker must be at the end of the token or else followed by punctuation.
|
||||
last := strings.LastIndex(word, word[:1])
|
||||
if last == 0 {
|
||||
continue Word
|
||||
}
|
||||
head, tail := word[:last+1], word[last+1:]
|
||||
for _, r := range tail {
|
||||
if !strings.ContainsRune(punctuation, r) {
|
||||
if last+1 != len(word) {
|
||||
r, _ := utf8.DecodeRuneInString(word[last+1:])
|
||||
if !unicode.IsPunct(r) {
|
||||
continue Word
|
||||
}
|
||||
}
|
||||
head, tail := word[:last+1], word[last+1:]
|
||||
b.Reset()
|
||||
b.WriteString(open)
|
||||
var wid int
|
||||
|
@ -72,6 +72,14 @@ func TestFont(t *testing.T) {
|
||||
`Visit <a href="http://golang.org" target="_blank">golang.org</a> now`},
|
||||
{"my talk ([[http://talks.golang.org/][slides here]])",
|
||||
`my talk (<a href="http://talks.golang.org/" target="_blank">slides here</a>)`},
|
||||
{"Markup—_especially_italic_text_—can easily be overused.",
|
||||
`Markup—<i>especially italic text</i>—can easily be overused.`},
|
||||
{"`go`get`'s codebase", // ascii U+0027 ' before s
|
||||
`<code>go get</code>'s codebase`},
|
||||
{"`go`get`’s codebase", // unicode right single quote U+2019 ’ before s
|
||||
`<code>go get</code>’s codebase`},
|
||||
{"a_variable_name",
|
||||
`a_variable_name`},
|
||||
}
|
||||
for _, test := range tests {
|
||||
out := font(test.in)
|
||||
|
Loading…
Reference in New Issue
Block a user