From 4477be72eead9d12fe016955571b211404ac6ccd Mon Sep 17 00:00:00 2001 From: yuin Date: Sun, 24 Oct 2021 17:49:45 +0900 Subject: [PATCH] Fix #235 --- extension/_test/linkify.txt | 16 +++++++++++++++- extension/linkify.go | 15 +++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/extension/_test/linkify.txt b/extension/_test/linkify.txt index 134f52b..4791f3c 100644 --- a/extension/_test/linkify.txt +++ b/extension/_test/linkify.txt @@ -171,9 +171,23 @@ http://server.intranet.acme.com:1313 //= = = = = = = = = = = = = = = = = = = = = = = =// -17 +18 //- - - - - - - - -// https://g.page/foo //- - - - - - - - -//

https://g.page/foo

//= = = = = = = = = = = = = = = = = = = = = = = =// + + +19: Trailing punctuation (specifically, ?, !, ., ,, :, *, _, and ~) will not be considered part of the autolink +//- - - - - - - - -// +__http://test.com/~/a__ +__http://test.com/~/__ +__http://test.com/~__ +__http://test.com/a/~__ +//- - - - - - - - -// +

http://test.com/~/a +http://test.com/~/ +http://test.com/~ +http://test.com/a/~

+//= = = = = = = = = = = = = = = = = = = = = = = =// diff --git a/extension/linkify.go b/extension/linkify.go index 42a87c8..2f046eb 100644 --- a/extension/linkify.go +++ b/extension/linkify.go @@ -273,9 +273,20 @@ func (s *linkifyParser) Parse(parent ast.Node, block text.Reader, pc parser.Cont s := segment.WithStop(segment.Start + 1) ast.MergeOrAppendTextSegment(parent, s) } - consumes += m[1] + i := m[1] - 1 + for ; i > 0; i-- { + c := line[i] + switch c { + case '?', '!', '.', ',', ':', '*', '_', '~': + default: + goto endfor + } + } +endfor: + i++ + consumes += i block.Advance(consumes) - n := ast.NewTextSegment(text.NewSegment(start, start+m[1])) + n := ast.NewTextSegment(text.NewSegment(start, start+i)) link := ast.NewAutoLink(typ, n) link.Protocol = protocol return link