all repos — grayfriday @ 31798e0eab52ebb57725b92dec2608c6d15ae533

blackfriday fork with a few changes

add testcase for GFM autolink
athom athom@126.com
Fri, 09 Aug 2013 17:24:26 +0800
commit

31798e0eab52ebb57725b92dec2608c6d15ae533

parent

16c09b01bd4fba32c47d078a1fce3096c2e4b59c

3 files changed, 46 insertions(+), 2 deletions(-)

jump to
M inline.goinline.go

@@ -620,7 +620,7 @@ }

// 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
M inline_test.goinline_test.go

@@ -462,6 +462,45 @@ }

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",
M markdown.gomarkdown.go

@@ -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.