* WIP: trim markdown for push notification * fix: golangci * fix: table regex * fix: regex code block * doc: add license * WIP: custom renderer with goldmark * WIP: update goldmark version to 1.38 * fix: use goldmark as parser * fix: remove table extension * fix: change buf to `strings.Builder` * fix: return original string, log warning if error * refactor: change `WriteString` to `WriteByte` * refactor: change if condition * refactor: use assertion * refactor: move to inline * fix: remove handle multiline Already handled by mobile * refactor: wrap same function * refactor: move strip markdown to `sendPushNotificationSync` * refactor: renaming variable aren't used * fix: move log to func `sendPushNotificationSync` * docs: add comment to `StripMarkdown` * fix: move assign message to else * appErr to err rename Co-authored-by: Agniva De Sarker <agnivade@yahoo.co.in> Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
43 строки
979 B
Go
43 строки
979 B
Go
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)
|
|
}
|