mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.2 KiB
51 lines
1.2 KiB
5 years ago
|
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
|
||
|
}
|