1
0
mirror of https://github.com/danog/blackfriday.git synced 2024-11-26 20:14:43 +01:00

add testcase for GFM autolink

This commit is contained in:
athom 2013-08-09 17:24:26 +08:00
parent 16c09b01bd
commit 31798e0eab
3 changed files with 46 additions and 2 deletions

View File

@ -620,7 +620,7 @@ func autoLink(p *parser, out *bytes.Buffer, data []byte, offset int) int {
// scan backward for a word boundary
rewind := 0
for offset-rewind > 0 && rewind <= 7 && isalnum(data[offset-rewind-1]) {
for offset-rewind > 0 && rewind <= 7 && isletter(data[offset-rewind-1]) {
rewind++
}
if rewind > 6 { // longest supported protocol is "mailto" which has 6 letters

View File

@ -462,6 +462,45 @@ func TestTags(t *testing.T) {
func TestAutoLink(t *testing.T) {
var tests = []string{
"http://foo.com/\n",
"<p><a href=\"http://foo.com/\">http://foo.com/</a></p>\n",
"1 http://foo.com/\n",
"<p>1 <a href=\"http://foo.com/\">http://foo.com/</a></p>\n",
"1http://foo.com/\n",
"<p>1<a href=\"http://foo.com/\">http://foo.com/</a></p>\n",
"1.http://foo.com/\n",
"<p>1.<a href=\"http://foo.com/\">http://foo.com/</a></p>\n",
"1. http://foo.com/\n",
"<ol>\n<li><a href=\"http://foo.com/\">http://foo.com/</a></li>\n</ol>\n",
"-http://foo.com/\n",
"<p>-<a href=\"http://foo.com/\">http://foo.com/</a></p>\n",
"- http://foo.com/\n",
"<ul>\n<li><a href=\"http://foo.com/\">http://foo.com/</a></li>\n</ul>\n",
"_http://foo.com/\n",
"<p>_<a href=\"http://foo.com/\">http://foo.com/</a></p>\n",
"令狐http://foo.com/\n",
"<p>令狐<a href=\"http://foo.com/\">http://foo.com/</a></p>\n",
"令狐 http://foo.com/\n",
"<p>令狐 <a href=\"http://foo.com/\">http://foo.com/</a></p>\n",
"ahttp://foo.com/\n",
"<p>ahttp://foo.com/</p>\n",
">http://foo.com/\n",
"<blockquote>\n<p><a href=\"http://foo.com/\">http://foo.com/</a></p>\n</blockquote>\n",
"> http://foo.com/\n",
"<blockquote>\n<p><a href=\"http://foo.com/\">http://foo.com/</a></p>\n</blockquote>\n",
"go to <http://foo.com/>\n",
"<p>go to <a href=\"http://foo.com/\">http://foo.com/</a></p>\n",

View File

@ -685,10 +685,15 @@ func isspace(c byte) bool {
return c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f' || c == '\v'
}
// Test if a character is letter.
func isletter(c byte) bool {
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
}
// Test if a character is a letter or a digit.
// TODO: check when this is looking for ASCII alnum and when it should use unicode
func isalnum(c byte) bool {
return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
return (c >= '0' && c <= '9') || isletter(c)
}
// Replace tab characters with spaces, aligning to the next TAB_SIZE column.