Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/markdown_it/rules_block/paragraph.py: 100%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

41 statements  

1"""Paragraph.""" 

2 

3import logging 

4 

5from ..common.utils import mdTrim 

6from .state_block import StateBlock 

7 

8LOGGER = logging.getLogger(__name__) 

9 

10 

11def paragraph(state: StateBlock, startLine: int, endLine: int, silent: bool) -> bool: 

12 LOGGER.debug( 

13 "entering paragraph: %s, %s, %s, %s", state, startLine, endLine, silent 

14 ) 

15 

16 nextLine = startLine + 1 

17 ruler = state.md.block.ruler 

18 terminatorRules = ruler.getRules("paragraph") 

19 endLine = state.lineMax 

20 

21 oldParentType = state.parentType 

22 state.parentType = "paragraph" 

23 

24 # jump line-by-line until empty one or EOF 

25 while nextLine < endLine: 

26 if state.isEmpty(nextLine): 

27 break 

28 # this would be a code block normally, but after paragraph 

29 # it's considered a lazy continuation regardless of what's there 

30 if state.sCount[nextLine] - state.blkIndent > 3: 

31 nextLine += 1 

32 continue 

33 

34 # quirk for blockquotes, this line should already be checked by that rule 

35 if state.sCount[nextLine] < 0: 

36 nextLine += 1 

37 continue 

38 

39 # Some tags can terminate paragraph without empty line. 

40 terminate = False 

41 for terminatorRule in terminatorRules: 

42 if terminatorRule(state, nextLine, endLine, True): 

43 terminate = True 

44 break 

45 

46 if terminate: 

47 break 

48 

49 nextLine += 1 

50 

51 content = mdTrim(state.getLines(startLine, nextLine, state.blkIndent, False)) 

52 

53 state.line = nextLine 

54 

55 token = state.push("paragraph_open", "p", 1) 

56 token.map = [startLine, state.line] 

57 

58 token = state.push("inline", "", 0) 

59 token.content = content 

60 token.map = [startLine, state.line] 

61 token.children = [] 

62 

63 token = state.push("paragraph_close", "p", -1) 

64 

65 state.parentType = oldParentType 

66 

67 return True