diff options
| author | 2022-12-16 11:20:22 +0000 | |
|---|---|---|
| committer | 2022-12-16 12:20:22 +0100 | |
| commit | eb08529f35ce33ed98c34fb48013f0f4a5fc9635 (patch) | |
| tree | 394fd774a943f5c33ce793c67b5865f2570b46c5 /vendor/github.com/yuin/goldmark/parser/auto_link.go | |
| parent | [bugfix] use match-sorter for filtering domain blocks (#1270) (diff) | |
| download | gotosocial-eb08529f35ce33ed98c34fb48013f0f4a5fc9635.tar.xz | |
[chore/bugfix] Switch markdown from blackfriday to goldmark (#1267)
Co-authored-by: Autumn! <autumnull@posteo.net>
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 000000000..726a50571 --- /dev/null +++ b/vendor/github.com/yuin/goldmark/parser/auto_link.go @@ -0,0 +1,42 @@ +package parser + +import ( + "github.com/yuin/goldmark/ast" + "github.com/yuin/goldmark/text" + "github.com/yuin/goldmark/util" +) + +type autoLinkParser struct { +} + +var defaultAutoLinkParser = &autoLinkParser{} + +// NewAutoLinkParser returns a new InlineParser that parses autolinks +// surrounded by '<' and '>' . +func NewAutoLinkParser() InlineParser { + return defaultAutoLinkParser +} + +func (s *autoLinkParser) Trigger() []byte { + return []byte{'<'} +} + +func (s *autoLinkParser) Parse(parent ast.Node, block text.Reader, pc Context) ast.Node { + line, segment := block.PeekLine() + stop := util.FindEmailIndex(line[1:]) + typ := ast.AutoLinkType(ast.AutoLinkEmail) + if stop < 0 { + stop = util.FindURLIndex(line[1:]) + typ = ast.AutoLinkURL + } + if stop < 0 { + return nil + } + stop++ + if stop >= len(line) || line[stop] != '>' { + return nil + } + value := ast.NewTextSegment(text.NewSegment(segment.Start+1, segment.Start+stop)) + block.Advance(stop + 1) + return ast.NewAutoLink(typ, value) +} |
