深入理解Hugo: Markdown Parser

package main
import (
    "fmt"
    "github.com/sunwei/gobyexample/modules/markdown/parser"
)
func main() {
    var r = newReader()
    d, _ := parser.Parse(r.lines)
    d.Walk(func(v any,
        ws parser.WalkState) parser.WalkStatus {
        b := v.(parser.Block)
        if ws == parser.WalkIn {
            fmt.Println("Walk in: ")
            fmt.Printf("%s\n", b)
        } else {
            fmt.Println("Walk out.")
        }
        return parser.WalkContinue
    })
}
type line struct {
    raw       string
    startChar string
}
func (l *line) Raw() string {
    return l.raw
}
func (l *line) StartChar() string {
    return l.startChar
}
type reader struct {
    lines []parser.Line
}
func newReader() *reader {
    return &reader{lines: []parser.Line{
        &line{raw: "### first blog\n", startChar: "#"},
        &line{raw: "Hello Blog\n", startChar: "H"},
    }}
}

Walk result Start from root

Walk in:
&{%!s(parser.BlockState=2) <nil> []}

In first child

Walk in:
&{{%!s(parser.BlockState=2)
%!s(*parser.heading=&{})
[%!s(*parser.headLine=&{first blog})]}
%!s(int=3)}
Walk out.

In second child

Walk in:
&{%!s(parser.BlockState=2)
%!s(*parser.paragraph=&{})
[%!s(*main.line=&{Hello Blog
 H})]}
Walk out.

Out root

Walk out.
Program exited.

Next example: Fsm.