@@ -1030,47 +1030,35 @@ type lineStat struct {
10301030}
10311031
10321032func isBlankLine (lineNum , level int , stats []lineStat ) bool {
1033- ret := true
1034- for i := len (stats ) - 1 - level ; i >= 0 ; i -- {
1035- ret = false
1033+ l := len (stats )
1034+ if l == 0 {
1035+ return true
1036+ }
1037+ for i := l - 1 - level ; i >= 0 ; i -- {
10361038 s := stats [i ]
1037- if s .lineNum == lineNum {
1038- if s .level < level && s .isBlank {
1039- return true
1040- } else if s .level == level {
1041- return s .isBlank
1042- }
1043- }
1044- if s .lineNum < lineNum {
1045- return ret
1039+ if s .lineNum == lineNum && s .level <= level {
1040+ return s .isBlank
1041+ } else if s .lineNum < lineNum {
1042+ break
10461043 }
10471044 }
1048- return ret
1045+ return false
10491046}
10501047
10511048func (p * parser ) parseBlocks (parent ast.Node , reader text.Reader , pc Context ) {
1052- pc .SetOpenedBlocks ([] Block {} )
1049+ pc .SetOpenedBlocks (nil )
10531050 blankLines := make ([]lineStat , 0 , 128 )
1054- var isBlank bool
10551051 for { // process blocks separated by blank lines
1056- _ , lines , ok := reader .SkipBlankLines ()
1052+ _ , _ , ok := reader .SkipBlankLines ()
10571053 if ! ok {
10581054 return
10591055 }
1060- lineNum , _ := reader .Position ()
1061- if lines != 0 {
1062- blankLines = blankLines [0 :0 ]
1063- l := len (pc .OpenedBlocks ())
1064- for i := 0 ; i < l ; i ++ {
1065- blankLines = append (blankLines , lineStat {lineNum - 1 , i , lines != 0 })
1066- }
1067- }
1068- isBlank = isBlankLine (lineNum - 1 , 0 , blankLines )
10691056 // first, we try to open blocks
1070- if p .openBlocks (parent , isBlank , reader , pc ) != newBlocksOpened {
1057+ if p .openBlocks (parent , true , reader , pc ) != newBlocksOpened {
10711058 return
10721059 }
10731060 reader .AdvanceLine ()
1061+ blankLines = blankLines [0 :0 ]
10741062 for { // process opened blocks line by line
10751063 openedBlocks := pc .OpenedBlocks ()
10761064 l := len (openedBlocks )
@@ -1096,15 +1084,15 @@ func (p *parser) parseBlocks(parent ast.Node, reader text.Reader, pc Context) {
10961084 // When current node is a container block and has no children,
10971085 // we try to open new child nodes
10981086 if state & HasChildren != 0 && i == lastIndex {
1099- isBlank = isBlankLine (lineNum - 1 , i + 1 , blankLines )
1087+ isBlank : = isBlankLine (lineNum - 1 , i + 1 , blankLines )
11001088 p .openBlocks (be .Node , isBlank , reader , pc )
11011089 break
11021090 }
11031091 continue
11041092 }
11051093 }
11061094 // current node may be closed or lazy continuation
1107- isBlank = isBlankLine (lineNum - 1 , i , blankLines )
1095+ isBlank : = isBlankLine (lineNum - 1 , i , blankLines )
11081096 thisParent := parent
11091097 if i != 0 {
11101098 thisParent = openedBlocks [i - 1 ].Node
0 commit comments