diff options
Diffstat (limited to 'vendor/github.com/yuin/goldmark/parser/auto_link.go')
| -rw-r--r-- | vendor/github.com/yuin/goldmark/parser/auto_link.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/vendor/github.com/yuin/goldmark/parser/auto_link.go b/vendor/github.com/yuin/goldmark/parser/auto_link.go new file mode 100644 index 0000000..726a505 --- /dev/null +++ b/vendor/github.com/yuin/goldmark/parser/auto_link.go | |||
| @@ -0,0 +1,42 @@ | |||
| 1 | package parser | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "github.com/yuin/goldmark/ast" | ||
| 5 | "github.com/yuin/goldmark/text" | ||
| 6 | "github.com/yuin/goldmark/util" | ||
| 7 | ) | ||
| 8 | |||
| 9 | type autoLinkParser struct { | ||
| 10 | } | ||
| 11 | |||
| 12 | var defaultAutoLinkParser = &autoLinkParser{} | ||
| 13 | |||
| 14 | // NewAutoLinkParser returns a new InlineParser that parses autolinks | ||
| 15 | // surrounded by '<' and '>' . | ||
| 16 | func NewAutoLinkParser() InlineParser { | ||
| 17 | return defaultAutoLinkParser | ||
| 18 | } | ||
| 19 | |||
| 20 | func (s *autoLinkParser) Trigger() []byte { | ||
| 21 | return []byte{'<'} | ||
| 22 | } | ||
| 23 | |||
| 24 | func (s *autoLinkParser) Parse(parent ast.Node, block text.Reader, pc Context) ast.Node { | ||
| 25 | line, segment := block.PeekLine() | ||
| 26 | stop := util.FindEmailIndex(line[1:]) | ||
| 27 | typ := ast.AutoLinkType(ast.AutoLinkEmail) | ||
| 28 | if stop < 0 { | ||
| 29 | stop = util.FindURLIndex(line[1:]) | ||
| 30 | typ = ast.AutoLinkURL | ||
| 31 | } | ||
| 32 | if stop < 0 { | ||
| 33 | return nil | ||
| 34 | } | ||
| 35 | stop++ | ||
| 36 | if stop >= len(line) || line[stop] != '>' { | ||
| 37 | return nil | ||
| 38 | } | ||
| 39 | value := ast.NewTextSegment(text.NewSegment(segment.Start+1, segment.Start+stop)) | ||
| 40 | block.Advance(stop + 1) | ||
| 41 | return ast.NewAutoLink(typ, value) | ||
| 42 | } | ||
