package parser

import (
	
)

// caption checks for a caption, it returns the caption data and a potential "headingID".
func ( *Parser) (,  []byte) ([]byte, string, int) {
	if !bytes.HasPrefix(, ) {
		return nil, "", 0
	}
	 := len()
	 = [:]
	 := LinesUntilEmpty()

	 = [:]

	,  := captionID()
	if  != "" {
		return [:], ,  + 
	}

	return , "",  + 
}

// LinesUntilEmpty scans lines up to the first empty line.
func ( []byte) int {
	,  := 0, 0

	for  < len() {
		++

		// find the end of this line
		for  < len() && [-1] != '\n' {
			++
		}

		if IsEmpty([:]) == 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 id
	for  = 0;  < -1 && ([] != '{' || [+1] != '#'); ++ {
	}
	for  =  + 1;  <  && [] != '}'; ++ {
	}
	// remains must be whitespace.
	for  :=  + 1;  < ; ++ {
		if !IsSpace([]) {
			return "", 0
		}
	}

	if  > 0 &&  > 0 && +2 <  {
		return string([+2 : ]), 
	}
	return "", 0
}