summaryrefslogtreecommitdiff
path: root/vendor/github.com/yuin/goldmark/parser/emphasis.go
diff options
context:
space:
mode:
authorLibravatar Autumn! <86073772+autumnull@users.noreply.github.com>2022-12-16 11:20:22 +0000
committerLibravatar GitHub <noreply@github.com>2022-12-16 12:20:22 +0100
commiteb08529f35ce33ed98c34fb48013f0f4a5fc9635 (patch)
tree394fd774a943f5c33ce793c67b5865f2570b46c5 /vendor/github.com/yuin/goldmark/parser/emphasis.go
parent[bugfix] use match-sorter for filtering domain blocks (#1270) (diff)
downloadgotosocial-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/emphasis.go')
-rw-r--r--vendor/github.com/yuin/goldmark/parser/emphasis.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/vendor/github.com/yuin/goldmark/parser/emphasis.go b/vendor/github.com/yuin/goldmark/parser/emphasis.go
new file mode 100644
index 000000000..488647117
--- /dev/null
+++ b/vendor/github.com/yuin/goldmark/parser/emphasis.go
@@ -0,0 +1,50 @@
+package parser
+
+import (
+ "github.com/yuin/goldmark/ast"
+ "github.com/yuin/goldmark/text"
+)
+
+type emphasisDelimiterProcessor struct {
+}
+
+func (p *emphasisDelimiterProcessor) IsDelimiter(b byte) bool {
+ return b == '*' || b == '_'
+}
+
+func (p *emphasisDelimiterProcessor) CanOpenCloser(opener, closer *Delimiter) bool {
+ return opener.Char == closer.Char
+}
+
+func (p *emphasisDelimiterProcessor) OnMatch(consumes int) ast.Node {
+ return ast.NewEmphasis(consumes)
+}
+
+var defaultEmphasisDelimiterProcessor = &emphasisDelimiterProcessor{}
+
+type emphasisParser struct {
+}
+
+var defaultEmphasisParser = &emphasisParser{}
+
+// NewEmphasisParser return a new InlineParser that parses emphasises.
+func NewEmphasisParser() InlineParser {
+ return defaultEmphasisParser
+}
+
+func (s *emphasisParser) Trigger() []byte {
+ return []byte{'*', '_'}
+}
+
+func (s *emphasisParser) Parse(parent ast.Node, block text.Reader, pc Context) ast.Node {
+ before := block.PrecendingCharacter()
+ line, segment := block.PeekLine()
+ node := ScanDelimiter(line, before, 1, defaultEmphasisDelimiterProcessor)
+ if node == nil {
+ return nil
+ }
+ node.Segment = segment.WithStop(segment.Start + node.OriginalLength)
+ block.Advance(node.OriginalLength)
+ pc.PushDelimiter(node)
+ return node
+}