| 1 |
"""Paragraph.""" |
| 2 |
import logging |
| 3 |
|
| 4 |
from .state_block import StateBlock |
| 5 |
|
| 6 |
LOGGER = logging.getLogger(__name__) |
| 7 |
|
| 8 |
|
| 9 |
def paragraph(state: StateBlock, startLine: int, endLine: int, silent: bool) -> bool: |
| 10 |
LOGGER.debug( |
| 11 |
"entering paragraph: %s, %s, %s, %s", state, startLine, endLine, silent |
| 12 |
) |
| 13 |
|
| 14 |
nextLine = startLine + 1 |
| 15 |
ruler = state.md.block.ruler |
| 16 |
terminatorRules = ruler.getRules("paragraph") |
| 17 |
endLine = state.lineMax |
| 18 |
|
| 19 |
oldParentType = state.parentType |
| 20 |
state.parentType = "paragraph" |
| 21 |
|
| 22 |
# jump line-by-line until empty one or EOF |
| 23 |
while nextLine < endLine: |
| 24 |
if state.isEmpty(nextLine): |
| 25 |
break |
| 26 |
# this would be a code block normally, but after paragraph |
| 27 |
# it's considered a lazy continuation regardless of what's there |
| 28 |
if state.sCount[nextLine] - state.blkIndent > 3: |
| 29 |
nextLine += 1 |
| 30 |
continue |
| 31 |
|
| 32 |
# quirk for blockquotes, this line should already be checked by that rule |
| 33 |
if state.sCount[nextLine] < 0: |
| 34 |
nextLine += 1 |
| 35 |
continue |
| 36 |
|
| 37 |
# Some tags can terminate paragraph without empty line. |
| 38 |
terminate = False |
| 39 |
for terminatorRule in terminatorRules: |
| 40 |
if terminatorRule(state, nextLine, endLine, True): |
| 41 |
terminate = True |
| 42 |
break |
| 43 |
|
| 44 |
if terminate: |
| 45 |
break |
| 46 |
|
| 47 |
nextLine += 1 |
| 48 |
|
| 49 |
content = state.getLines(startLine, nextLine, state.blkIndent, False).strip() |
| 50 |
|
| 51 |
state.line = nextLine |
| 52 |
|
| 53 |
token = state.push("paragraph_open", "p", 1) |
| 54 |
token.map = [startLine, state.line] |
| 55 |
|
| 56 |
token = state.push("inline", "", 0) |
| 57 |
token.content = content |
| 58 |
token.map = [startLine, state.line] |
| 59 |
token.children = [] |
| 60 |
|
| 61 |
token = state.push("paragraph_close", "p", -1) |
| 62 |
|
| 63 |
state.parentType = oldParentType |
| 64 |
|
| 65 |
return True |