package parserimport ()// sFigureLine checks if there's a figure line (e.g., !--- ) at the beginning of data,// and returns the end index if so, or 0 otherwise.func sFigureLine( []byte, string) ( int, string) { , := 0, 0 := len()// skip up to three spacesfor < && < 3 && [] == ' ' { ++ }// check for the marker characters: !if +1 >= {return0, "" }if [] != '!' || [+1] != '-' {return0, "" } ++ := [] // i.e. the -// the whole line must be the same char or whitespacefor < && [] == { ++ ++ }// the marker char must occur at least 3 timesif < 3 {return0, "" } = string([- : ])// if this is the end marker, it must match the beginning markerif != "" && != {return0, "" }// there is no syntax modifier although it might be an idea to re-use this space for something? = skipChar(, , ' ')if >= || [] != '\n' {if == {return , }return0, "" }return + 1, // Take newline into account.}// figureBlock returns the end index if data contains a figure block at the beginning,// or 0 otherwise. It writes to out if doRender is true, otherwise it has no side effects.// If doRender is true, a final newline is mandatory to recognize the figure block.func ( *Parser) ( []byte, bool) int { , := sFigureLine(, "")if == 0 || >= len() {return0 }varbytes.Bufferfor {// safe to assume beg < len(data)// check for the end of the code block , := sFigureLine([:], )if != 0 { += break }// copy the current line := skipUntilChar(, , '\n') + 1// did we reach the end of the buffer without a closing marker?if >= len() {return0 }// verbatim copy to the working bufferif { .Write([:]) } = }if ! {return } := &ast.CaptionFigure{} .AddBlock() .Block(.Bytes())defer .Finalize()if , , := .caption([:], []byte("Figure: ")); > 0 { := &ast.Caption{} .Inline(, ) .HeadingID = .addChild() += }return}
The pages are generated with Goldsv0.8.2. (GOOS=linux 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 @zigo_101 (reachable from the left QR code) to get the latest news of Golds.