codekingpro/portable-devtools
114k
1"""Paragraph."""2 3import logging4 5from .state_block import StateBlock6 7LOGGER = logging.getLogger(__name__)8 9 10def paragraph(state: StateBlock, startLine: int, endLine: int, silent: bool) -> bool:11 LOGGER.debug(12 "entering paragraph: %s, %s, %s, %s", state, startLine, endLine, silent13 )14 15 nextLine = startLine + 116 ruler = state.md.block.ruler17 terminatorRules = ruler.getRules("paragraph")18 endLine = state.lineMax19 20 oldParentType = state.parentType21 state.parentType = "paragraph"22 23 # jump line-by-line until empty one or EOF24 while nextLine < endLine:25 if state.isEmpty(nextLine):26 break27 # this would be a code block normally, but after paragraph28 # it's considered a lazy continuation regardless of what's there29 if state.sCount[nextLine] - state.blkIndent > 3:30 nextLine += 131 continue32 33 # quirk for blockquotes, this line should already be checked by that rule34 if state.sCount[nextLine] < 0:35 nextLine += 136 continue37 38 # Some tags can terminate paragraph without empty line.39 terminate = False40 for terminatorRule in terminatorRules:41 if terminatorRule(state, nextLine, endLine, True):42 terminate = True43 break44 45 if terminate:46 break47 48 nextLine += 149 50 content = state.getLines(startLine, nextLine, state.blkIndent, False).strip()51 52 state.line = nextLine53 54 token = state.push("paragraph_open", "p", 1)55 token.map = [startLine, state.line]56 57 token = state.push("inline", "", 0)58 token.content = content59 token.map = [startLine, state.line]60 token.children = []61 62 token = state.push("paragraph_close", "p", -1)63 64 state.parentType = oldParentType65 66 return True67 