@@ -33,13 +33,13 @@ var (
33
33
type Formatter interface {
34
34
// Put makes sure that a string is propperly written to.
35
35
// One thing Put should do is making sure the string is propperly escaped
36
- // Nice indicates if the text should be formatted or converted
37
- Put (text string , nice bool )
36
+ // pretty indicates if the text should be formatted or converted
37
+ Put (text string , pretty bool )
38
38
39
39
// WriteURL writes the URL to the writer using match as a display name.
40
- // italics indicates wether or not it should be italic. If nice is set,
40
+ // italics indicates wether or not it should be italic. If pretty is set,
41
41
// also turn `` and '' into appropirate quotes.
42
- WriteURL (url , match string , italics , nice bool )
42
+ WriteURL (url , match string , italics , pretty bool )
43
43
44
44
StartPara ()
45
45
PreParaLine (line string )
@@ -77,10 +77,13 @@ var (
77
77
htmlEndH = []byte ("</h3>\n " )
78
78
)
79
79
80
- // Escape escapes text for HTML. If nice is set,
80
+ // Escape escapes text for HTML. If pretty is set,
81
81
// also turn `` and '' into appropirate quotes.
82
- func (f * htmlFormatter ) Put (text string , nice bool ) {
83
- if nice {
82
+ func (f * htmlFormatter ) Put (text string , pretty bool ) {
83
+ if pretty {
84
+ // In the first pass, we convert `` and '' into their unicode equivalents.
85
+ // This prevents them from being escaped in HTMLEscape.
86
+ text = convertQuotes (text )
84
87
var buf bytes.Buffer
85
88
template .HTMLEscape (& buf , []byte (text ))
86
89
// Now we convert the unicode quotes to their HTML escaped entities to maintain old behavior.
@@ -92,7 +95,7 @@ func (f *htmlFormatter) Put(text string, nice bool) {
92
95
template .HTMLEscape (f .out , []byte (text ))
93
96
}
94
97
95
- func (f * htmlFormatter ) WriteURL (url , match string , italics , nice bool ) {
98
+ func (f * htmlFormatter ) WriteURL (url , match string , italics , pretty bool ) {
96
99
if len (url ) > 0 {
97
100
f .out .Write (htmlPreLink )
98
101
f .Put (url , false )
@@ -101,7 +104,7 @@ func (f *htmlFormatter) WriteURL(url, match string, italics, nice bool) {
101
104
if italics {
102
105
f .out .Write (htmlStartI )
103
106
}
104
- f .Put (match , nice )
107
+ f .Put (match , pretty )
105
108
if italics {
106
109
f .out .Write (htmlEndI )
107
110
}
@@ -169,22 +172,22 @@ var newline = []byte("\n")
169
172
var whiteSpace = []byte (" " )
170
173
var prefix = []byte ("// " )
171
174
172
- // Escape escapes text for HTML. If nice is set,
175
+ // Escape escapes text for HTML. If pretty is set,
173
176
// also turn `` and '' into appropirate quotes.
174
- func (f * textFormatter ) Put (text string , nice bool ) {
175
- if nice {
177
+ func (f * textFormatter ) Put (text string , pretty bool ) {
178
+ if pretty {
176
179
text = convertQuotes (text )
177
180
f .line += text
178
181
return
179
182
}
180
183
f .out .Write ([]byte (text ))
181
184
}
182
185
183
- func (f * textFormatter ) WriteURL (url , match string , italics , nice bool ) {
186
+ func (f * textFormatter ) WriteURL (url , match string , italics , pretty bool ) {
184
187
if url == "" {
185
188
url = match
186
189
}
187
- f .Put (url , nice )
190
+ f .Put (url , pretty )
188
191
}
189
192
190
193
func (f * textFormatter ) StartPara () {
@@ -295,18 +298,18 @@ var (
295
298
mdLinkEnd = []byte (")" )
296
299
)
297
300
298
- // Escape escapes text for HTML. If nice is set,
301
+ // Escape escapes text for HTML. If pretty is set,
299
302
// also turn `` and '' into appropirate quotes.
300
- func (f * markdownFormatter ) Put (text string , nice bool ) {
303
+ func (f * markdownFormatter ) Put (text string , pretty bool ) {
301
304
text = mdEscape .ReplaceAllString (text , `\$1` )
302
305
f .out .Write ([]byte (text ))
303
306
}
304
307
305
- func (f * markdownFormatter ) WriteURL (url , match string , italics , nice bool ) {
308
+ func (f * markdownFormatter ) WriteURL (url , match string , italics , pretty bool ) {
306
309
if len (url ) > 0 {
307
310
f .out .Write (mdLinkStart )
308
311
}
309
- f .Put (match , nice )
312
+ f .Put (match , pretty )
310
313
if italics {
311
314
f .out .Write (htmlStartI )
312
315
}
@@ -497,10 +500,10 @@ var matchRx = lazyregexp.New(`(` + urlRx + `)|(` + identRx + `)`)
497
500
// the corresponding map value is the empty string, the URL is not converted
498
501
// into a link). Go identifiers that appear in the words map are italicized; if
499
502
// the corresponding map value is not the empty string, it is considered a URL
500
- // and the word is converted into a link. If nice is set, the remaining text's
503
+ // and the word is converted into a link. If pretty is set, the remaining text's
501
504
// appearance is improved where it makes sense (e.g., `` is turned into “
502
505
// and '' into ”).
503
- func emphasize (w io.Writer , f Formatter , line string , words map [string ]string , nice bool ) {
506
+ func emphasize (w io.Writer , f Formatter , line string , words map [string ]string , pretty bool ) {
504
507
for {
505
508
m := matchRx .FindStringSubmatchIndex (line )
506
509
if m == nil {
@@ -510,10 +513,10 @@ func emphasize(w io.Writer, f Formatter, line string, words map[string]string, n
510
513
511
514
// write text before match
512
515
pre := line [0 :m [0 ]]
513
- if nice {
516
+ if pretty {
514
517
pre = convertQuotes (line [0 :m [0 ]])
515
518
}
516
- f .Put (pre , nice )
519
+ f .Put (pre , pretty )
517
520
518
521
// adjust match for URLs
519
522
match := line [m [0 ]:m [1 ]]
@@ -552,20 +555,20 @@ func emphasize(w io.Writer, f Formatter, line string, words map[string]string, n
552
555
}
553
556
italics = false // don't italicize URLs
554
557
}
555
- if nice {
558
+ if pretty {
556
559
match = convertQuotes (match )
557
560
}
558
561
559
562
// write match
560
- f .WriteURL (url , match , italics , nice )
563
+ f .WriteURL (url , match , italics , pretty )
561
564
562
565
// advance
563
566
line = line [m [1 ]:]
564
567
}
565
- if nice {
568
+ if pretty {
566
569
line = convertQuotes (line )
567
570
}
568
- f .Put (line , nice )
571
+ f .Put (line , pretty )
569
572
}
570
573
571
574
func convertQuotes (text string ) string {
0 commit comments