Skip to content

Commit 60e14d7

Browse files
committed
format: parse task list html
1 parent 56e2adb commit 60e14d7

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

format/htmlparser.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,8 @@ func (parser *HTMLParser) tagToString(node *html.Node, ctx Context) string {
348348
return parser.imgToString(node, ctx)
349349
case "hr":
350350
return parser.HorizontalLine
351+
case "input":
352+
return parser.inputToString(node, ctx)
351353
case "pre":
352354
var preStr, language string
353355
if node.FirstChild != nil && node.FirstChild.Type == html.ElementNode && node.FirstChild.Data == "code" {
@@ -371,6 +373,17 @@ func (parser *HTMLParser) tagToString(node *html.Node, ctx Context) string {
371373
}
372374
}
373375

376+
func (parser *HTMLParser) inputToString(node *html.Node, ctx Context) string {
377+
if len(ctx.TagStack) > 1 && ctx.TagStack[len(ctx.TagStack)-2] == "li" {
378+
_, checked := parser.maybeGetAttribute(node, "checked")
379+
if checked {
380+
return "[x]"
381+
}
382+
return "[ ]"
383+
}
384+
return parser.nodeToTagAwareString(node.FirstChild, ctx)
385+
}
386+
374387
func (parser *HTMLParser) singleNodeToString(node *html.Node, ctx Context) TaggedString {
375388
switch node.Type {
376389
case html.TextNode:

0 commit comments

Comments
 (0)