diff --git a/inline.go b/inline.go index 1070762..db02091 100644 --- a/inline.go +++ b/inline.go @@ -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 diff --git a/inline_test.go b/inline_test.go index f621529..60f764c 100644 --- a/inline_test.go +++ b/inline_test.go @@ -462,6 +462,45 @@ func TestTags(t *testing.T) { func TestAutoLink(t *testing.T) { var tests = []string{ + "http://foo.com/\n", + "
\n", + + "1 http://foo.com/\n", + "\n", + + "1http://foo.com/\n", + "\n", + + "1.http://foo.com/\n", + "\n", + + "1. http://foo.com/\n", + "ahttp://foo.com/
\n", + + ">http://foo.com/\n", + "\n\n\n", + + "> http://foo.com/\n", + "
\n\n\n", + "go to
go to http://foo.com/
\n", diff --git a/markdown.go b/markdown.go index 77e93e8..322300f 100644 --- a/markdown.go +++ b/markdown.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.