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

40 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-07 06:07 +0000

1"""Paragraph.""" 

2import logging 

3 

4from ..ruler import Ruler 

5from .state_block import StateBlock 

6 

7LOGGER = logging.getLogger(__name__) 

8 

9 

10def paragraph(state: StateBlock, startLine: int, endLine: int, silent: bool = False): 

11 LOGGER.debug( 

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

13 ) 

14 

15 nextLine = startLine + 1 

16 ruler: Ruler = state.md.block.ruler 

17 terminatorRules = ruler.getRules("paragraph") 

18 endLine = state.lineMax 

19 

20 oldParentType = state.parentType 

21 state.parentType = "paragraph" 

22 

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

24 while nextLine < endLine: 

25 if state.isEmpty(nextLine): 

26 break 

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

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

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

30 nextLine += 1 

31 continue 

32 

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

34 if state.sCount[nextLine] < 0: 

35 nextLine += 1 

36 continue 

37 

38 # Some tags can terminate paragraph without empty line. 

39 terminate = False 

40 for terminatorRule in terminatorRules: 

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

42 terminate = True 

43 break 

44 

45 if terminate: 

46 break 

47 

48 nextLine += 1 

49 

50 content = state.getLines(startLine, nextLine, state.blkIndent, False).strip() 

51 

52 state.line = nextLine 

53 

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

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

56 

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

58 token.content = content 

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

60 token.children = [] 

61 

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

63 

64 state.parentType = oldParentType 

65 

66 return True