Source File
code_span.go
Belonging Package
github.com/yuin/goldmark/parser
package parserimport ()type codeSpanParser struct {}var defaultCodeSpanParser = &codeSpanParser{}// NewCodeSpanParser return a new InlineParser that parses inline codes// surrounded by '`' .func () InlineParser {return defaultCodeSpanParser}func ( *codeSpanParser) () []byte {return []byte{'`'}}func ( *codeSpanParser) ( ast.Node, text.Reader, Context) ast.Node {, := .PeekLine():= 0for ; < len() && [] == '`'; ++ {}.Advance(), := .Position():= ast.NewCodeSpan()for {, := .PeekLine()if == nil {.SetPosition(, )return ast.NewTextSegment(.WithStop(.Start + ))}for := 0; < len(); ++ {:= []if == '`' {:=for ; < len() && [] == '`'; ++ {}:= -if == && ( >= len() || [] != '`') {= .WithStop(.Start + - )if !.IsEmpty() {.AppendChild(, ast.NewRawTextSegment())}.Advance()goto}}}.AppendChild(, ast.NewRawTextSegment()).AdvanceLine()}:if !.IsBlank(.Source()) {// trim first halfspace and last halfspace:= .FirstChild().(*ast.Text).Segment:= trueif !(!.IsEmpty() && isSpaceOrNewline(.Source()[.Start])) {= false}= .LastChild().(*ast.Text).Segmentif !(!.IsEmpty() && isSpaceOrNewline(.Source()[.Stop-1])) {= false}if {:= .FirstChild().(*ast.Text):= .Segment.Segment = .WithStart(.Start + 1)= .LastChild().(*ast.Text)= .LastChild().(*ast.Text).Segment.Segment = .WithStop(.Stop - 1)}}return}func isSpaceOrNewline( byte) bool {return == ' ' || == '\n'}
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |