package parserimport ()// caption checks for a caption, it returns the caption data and a potential "headingID".func ( *Parser) (, []byte) ([]byte, string, int) {if !bytes.HasPrefix(, ) {returnnil, "", 0 } := len() = [:] := LinesUntilEmpty() = [:] , := captionID()if != "" {return [:], , + }return , "", + }// LinesUntilEmpty scans lines up to the first empty line.func ( []byte) int { , := 0, 0for < len() { ++// find the end of this linefor < len() && [-1] != '\n' { ++ }ifIsEmpty([:]) == 0 { = continue }break }return}// captionID checks if the caption *ends* in {#....}. If so the text after {# is taken to be// the ID/anchor of the entire figure block.func captionID( []byte) (string, int) { := len() , := 0, 0// find start/end of heading idfor = 0; < -1 && ([] != '{' || [+1] != '#'); ++ { }for = + 1; < && [] != '}'; ++ { }// remains must be whitespace.for := + 1; < ; ++ {if !IsSpace([]) {return"", 0 } }if > 0 && > 0 && +2 < {returnstring([+2 : ]), }return"", 0}
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.