Source File
strikethrough.go
Belonging Package
github.com/yuin/goldmark/extension
package extension
import (
gast
)
type strikethroughDelimiterProcessor struct {
}
func ( *strikethroughDelimiterProcessor) ( byte) bool {
return == '~'
}
func ( *strikethroughDelimiterProcessor) (, *parser.Delimiter) bool {
return .Char == .Char
}
func ( *strikethroughDelimiterProcessor) ( int) gast.Node {
return ast.NewStrikethrough()
}
var defaultStrikethroughDelimiterProcessor = &strikethroughDelimiterProcessor{}
type strikethroughParser struct {
}
var defaultStrikethroughParser = &strikethroughParser{}
func () parser.InlineParser {
return defaultStrikethroughParser
}
func ( *strikethroughParser) () []byte {
return []byte{'~'}
}
func ( *strikethroughParser) ( gast.Node, text.Reader, parser.Context) gast.Node {
:= .PrecendingCharacter()
, := .PeekLine()
:= parser.ScanDelimiter(, , 2, defaultStrikethroughDelimiterProcessor)
if == nil {
return nil
}
.Segment = .WithStop(.Start + .OriginalLength)
.Advance(.OriginalLength)
.PushDelimiter()
return
}
}
type StrikethroughHTMLRenderer struct {
html.Config
}
func ( ...html.Option) renderer.NodeRenderer {
:= &StrikethroughHTMLRenderer{
Config: html.NewConfig(),
}
for , := range {
.SetHTMLOption(&.Config)
}
return
}
var StrikethroughAttributeFilter = html.GlobalAttributeFilter
func ( *StrikethroughHTMLRenderer) ( util.BufWriter, []byte, gast.Node, bool) (gast.WalkStatus, error) {
if {
if .Attributes() != nil {
_, _ = .WriteString("<del")
html.RenderAttributes(, , StrikethroughAttributeFilter)
_ = .WriteByte('>')
} else {
_, _ = .WriteString("<del>")
}
} else {
_, _ = .WriteString("</del>")
}
return gast.WalkContinue, nil
}
type strikethrough struct {
}
var Strikethrough = &strikethrough{}
func ( *strikethrough) ( goldmark.Markdown) {
.Parser().AddOptions(parser.WithInlineParsers(
util.Prioritized(NewStrikethroughParser(), 500),
))
.Renderer().AddOptions(renderer.WithNodeRenderers(
util.Prioritized(NewStrikethroughHTMLRenderer(), 500),
))
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin 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 @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |