Source File
tasklist.go
Belonging Package
github.com/yuin/goldmark/extension
package extension
import (
gast
)
var taskListRegexp = regexp.MustCompile(`^\[([\sxX])\]\s*`)
type taskCheckBoxParser struct {
}
var defaultTaskCheckBoxParser = &taskCheckBoxParser{}
func () parser.InlineParser {
return defaultTaskCheckBoxParser
}
func ( *taskCheckBoxParser) () []byte {
return []byte{'['}
}
if .Parent() == nil || .Parent().FirstChild() != {
return nil
}
if , := .Parent().(*gast.ListItem); ! {
return nil
}
, := .PeekLine()
:= taskListRegexp.FindSubmatchIndex()
if == nil {
return nil
}
:= [[2]:[3]][0]
.Advance([1])
:= == 'x' || == 'X'
return ast.NewTaskCheckBox()
}
}
type TaskCheckBoxHTMLRenderer struct {
html.Config
}
func ( ...html.Option) renderer.NodeRenderer {
:= &TaskCheckBoxHTMLRenderer{
Config: html.NewConfig(),
}
for , := range {
.SetHTMLOption(&.Config)
}
return
}
func ( *TaskCheckBoxHTMLRenderer) ( renderer.NodeRendererFuncRegisterer) {
.Register(ast.KindTaskCheckBox, .renderTaskCheckBox)
}
func ( *TaskCheckBoxHTMLRenderer) ( util.BufWriter, []byte, gast.Node, bool) (gast.WalkStatus, error) {
if ! {
return gast.WalkContinue, nil
}
:= .(*ast.TaskCheckBox)
if .IsChecked {
.WriteString(`<input checked="" disabled="" type="checkbox"`)
} else {
.WriteString(`<input disabled="" type="checkbox"`)
}
if .XHTML {
.WriteString(" /> ")
} else {
.WriteString("> ")
}
return gast.WalkContinue, nil
}
type taskList struct {
}
var TaskList = &taskList{}
func ( *taskList) ( goldmark.Markdown) {
.Parser().AddOptions(parser.WithInlineParsers(
util.Prioritized(NewTaskCheckBoxParser(), 0),
))
.Renderer().AddOptions(renderer.WithNodeRenderers(
util.Prioritized(NewTaskCheckBoxHTMLRenderer(), 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. |