Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
b9474de2
Commit
b9474de2
authored
Feb 02, 2012
by
Gary Burd
Committed by
Robert Griesemer
Feb 02, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
go/doc: Fix URL linking in ToHTML.
Fixes issue: 2832 R=rsc, gri CC=golang-dev
https://golang.org/cl/5616060
parent
cce3de79
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
4 deletions
+30
-4
src/pkg/go/doc/comment.go
src/pkg/go/doc/comment.go
+4
-4
src/pkg/go/doc/comment_test.go
src/pkg/go/doc/comment_test.go
+26
-0
No files found.
src/pkg/go/doc/comment.go
View file @
b9474de2
...
...
@@ -56,7 +56,7 @@ const (
filePart
+
`([:.,]`
+
filePart
+
`)*`
)
var
matchRx
=
regexp
.
MustCompile
(
`(`
+
identRx
+
`)|(`
+
url
Rx
+
`)`
)
var
matchRx
=
regexp
.
MustCompile
(
`(`
+
urlRx
+
`)|(`
+
ident
Rx
+
`)`
)
var
(
html_a
=
[]
byte
(
`<a href="`
)
...
...
@@ -87,7 +87,7 @@ func emphasize(w io.Writer, line string, words map[string]string, nice bool) {
if
m
==
nil
{
break
}
// m >= 6 (two parenthesized sub-regexps in matchRx, 1st one is
ident
Rx)
// m >= 6 (two parenthesized sub-regexps in matchRx, 1st one is
url
Rx)
// write text before match
commentEscape
(
w
,
line
[
0
:
m
[
0
]],
nice
)
...
...
@@ -99,8 +99,8 @@ func emphasize(w io.Writer, line string, words map[string]string, nice bool) {
if
words
!=
nil
{
url
,
italics
=
words
[
string
(
match
)]
}
if
m
[
2
]
<
0
{
//
didn't
match against first parenthesized sub-regexp; must be match against urlRx
if
m
[
2
]
>=
0
{
// match against first parenthesized sub-regexp; must be match against urlRx
if
!
italics
{
// no alternative URL in words list, use match instead
url
=
string
(
match
)
...
...
src/pkg/go/doc/comment_test.go
View file @
b9474de2
...
...
@@ -5,6 +5,7 @@
package
doc
import
(
"bytes"
"reflect"
"testing"
)
...
...
@@ -81,3 +82,28 @@ func TestBlocks(t *testing.T) {
}
}
}
var
emphasizeTests
=
[]
struct
{
in
string
out
string
}{
{
"http://www.google.com/"
,
`<a href="http://www.google.com/">http://www.google.com/</a>`
},
{
"https://www.google.com/"
,
`<a href="https://www.google.com/">https://www.google.com/</a>`
},
{
"http://www.google.com/path."
,
`<a href="http://www.google.com/path">http://www.google.com/path</a>.`
},
{
"(http://www.google.com/)"
,
`(<a href="http://www.google.com/">http://www.google.com/</a>)`
},
{
"Foo bar http://example.com/ quux!"
,
`Foo bar <a href="http://example.com/">http://example.com/</a> quux!`
},
{
"Hello http://example.com/%2f/ /world."
,
`Hello <a href="http://example.com/%2f/">http://example.com/%2f/</a> /world.`
},
{
"Lorem http: ipsum //host/path"
,
"Lorem http: ipsum //host/path"
},
{
"javascript://is/not/linked"
,
"javascript://is/not/linked"
},
}
func
TestEmphasize
(
t
*
testing
.
T
)
{
for
i
,
tt
:=
range
emphasizeTests
{
var
buf
bytes
.
Buffer
emphasize
(
&
buf
,
tt
.
in
,
nil
,
true
)
out
:=
buf
.
String
()
if
out
!=
tt
.
out
{
t
.
Errorf
(
"#%d: mismatch
\n
have: %v
\n
want: %v"
,
i
,
out
,
tt
.
out
)
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment