RST: improve line blocks (#16518)
This commit is contained in:
parent
17992fca1d
commit
5984f7a7dd
5 changed files with 68 additions and 17 deletions
|
|
@ -1147,7 +1147,8 @@ proc isAdornmentHeadline(p: RstParser, adornmentIdx: int): bool =
|
|||
proc isLineBlock(p: RstParser): bool =
|
||||
var j = tokenAfterNewline(p)
|
||||
result = currentTok(p).col == p.tok[j].col and p.tok[j].symbol == "|" or
|
||||
p.tok[j].col > currentTok(p).col
|
||||
p.tok[j].col > currentTok(p).col or
|
||||
p.tok[j].symbol == "\n"
|
||||
|
||||
proc predNL(p: RstParser): bool =
|
||||
result = true
|
||||
|
|
@ -1245,21 +1246,28 @@ proc whichSection(p: RstParser): RstNodeKind =
|
|||
|
||||
proc parseLineBlock(p: var RstParser): PRstNode =
|
||||
result = nil
|
||||
if nextTok(p).kind == tkWhite:
|
||||
if nextTok(p).kind in {tkWhite, tkIndent}:
|
||||
var col = currentTok(p).col
|
||||
result = newRstNode(rnLineBlock)
|
||||
pushInd(p, p.tok[p.idx + 2].col)
|
||||
inc p.idx, 2
|
||||
while true:
|
||||
var item = newRstNode(rnLineBlockItem)
|
||||
parseSection(p, item)
|
||||
if nextTok(p).kind == tkWhite:
|
||||
if nextTok(p).symbol.len > 1: # pass additional indentation after '| '
|
||||
item.text = nextTok(p).symbol
|
||||
inc p.idx, 2
|
||||
pushInd(p, p.tok[p.idx].col)
|
||||
parseSection(p, item)
|
||||
popInd(p)
|
||||
else: # tkIndent => add an empty line
|
||||
item.text = "\n"
|
||||
inc p.idx, 1
|
||||
result.add(item)
|
||||
if currentTok(p).kind == tkIndent and currentTok(p).ival == col and
|
||||
nextTok(p).symbol == "|" and p.tok[p.idx + 2].kind == tkWhite:
|
||||
inc p.idx, 3
|
||||
nextTok(p).symbol == "|" and
|
||||
p.tok[p.idx + 2].kind in {tkWhite, tkIndent}:
|
||||
inc p.idx, 1
|
||||
else:
|
||||
break
|
||||
popInd(p)
|
||||
|
||||
proc parseParagraph(p: var RstParser, result: PRstNode) =
|
||||
while true:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue