package parser

import (
	
	
	
)

type codeBlockParser struct {
}
CodeBlockParser is a BlockParser implementation that parses indented code blocks.
NewCodeBlockParser returns a new BlockParser that parses code blocks.
func () BlockParser {
	return defaultCodeBlockParser
}

func ( *codeBlockParser) () []byte {
	return nil
}

func ( *codeBlockParser) ( ast.Node,  text.Reader,  Context) (ast.Node, State) {
	,  := .PeekLine()
	,  := util.IndentPosition(, .LineOffset(), 4)
	if  < 0 || util.IsBlank() {
		return nil, NoChildren
	}
	 := ast.NewCodeBlock()
	.AdvanceAndSetPadding(, )
	_,  = .PeekLine()
	.Lines().Append()
	.Advance(.Len() - 1)
	return , NoChildren

}

func ( *codeBlockParser) ( ast.Node,  text.Reader,  Context) State {
	,  := .PeekLine()
	if util.IsBlank() {
		.Lines().Append(.TrimLeftSpaceWidth(4, .Source()))
		return Continue | NoChildren
	}
	,  := util.IndentPosition(, .LineOffset(), 4)
	if  < 0 {
		return Close
	}
	.AdvanceAndSetPadding(, )
	_,  = .PeekLine()
if code block line starts with a tab, keep a tab as it is.
	if .Padding != 0 {
		preserveLeadingTabInCodeBlock(&, , 0)
	}

	.Lines().Append()
	.Advance(.Len() - 1)
	return Continue | NoChildren
}

trim trailing blank lines
	 := .Lines()
	 := .Len() - 1
	 := .Source()
	for  >= 0 {
		 := .At()
		if util.IsBlank(.Value()) {
			--
		} else {
			break
		}
	}
	.SetSliced(0, +1)
}

func ( *codeBlockParser) () bool {
	return false
}

func ( *codeBlockParser) () bool {
	return true
}

func ( *text.Segment,  text.Reader,  int) {
	 := .LineOffset() + 
	,  := .Position()
	.SetPosition(, text.NewSegment(.Start-1, .Stop))
	if  == .LineOffset() {
		.Padding = 0
		.Start--
	}
	.SetPosition(, )