mirror of
https://github.com/yuin/goldmark
synced 2025-03-04 23:04:52 +00:00
feat(extension/tasklist): Preserve TaskList item source positions to allow Tasks to be Accomplished later.
This commit is contained in:
parent
c15e394c27
commit
32a63fedc1
2 changed files with 17 additions and 2 deletions
|
|
@ -2,12 +2,18 @@ package ast
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
gast "github.com/yuin/goldmark/ast"
|
||||
"github.com/yuin/goldmark/text"
|
||||
)
|
||||
|
||||
// A TaskCheckBox struct represents a checkbox of a task list.
|
||||
type TaskCheckBox struct {
|
||||
gast.BaseInline
|
||||
|
||||
// Segment is a position in a source text.
|
||||
Segment text.Segment
|
||||
|
||||
IsChecked bool
|
||||
}
|
||||
|
||||
|
|
@ -33,3 +39,11 @@ func NewTaskCheckBox(checked bool) *TaskCheckBox {
|
|||
IsChecked: checked,
|
||||
}
|
||||
}
|
||||
|
||||
// NewTaskCheckBoxSegment returns a new TaskCheckBox node with the given source position.
|
||||
func NewTaskCheckBoxSegment(checked bool, segment text.Segment) *TaskCheckBox {
|
||||
return &TaskCheckBox{
|
||||
IsChecked: checked,
|
||||
Segment: segment,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ func (s *taskCheckBoxParser) Parse(parent gast.Node, block text.Reader, pc parse
|
|||
if _, ok := parent.Parent().(*gast.ListItem); !ok {
|
||||
return nil
|
||||
}
|
||||
line, _ := block.PeekLine()
|
||||
line, lineSegment := block.PeekLine()
|
||||
m := taskListRegexp.FindSubmatchIndex(line)
|
||||
if m == nil {
|
||||
return nil
|
||||
|
|
@ -55,7 +55,8 @@ func (s *taskCheckBoxParser) Parse(parent gast.Node, block text.Reader, pc parse
|
|||
value := line[m[2]:m[3]][0]
|
||||
block.Advance(m[1])
|
||||
checked := value == 'x' || value == 'X'
|
||||
return ast.NewTaskCheckBox(checked)
|
||||
segment := text.NewSegment(lineSegment.Start+m[2], lineSegment.Start+m[3])
|
||||
return ast.NewTaskCheckBoxSegment(checked, segment)
|
||||
}
|
||||
|
||||
func (s *taskCheckBoxParser) CloseBlock(parent gast.Node, pc parser.Context) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue