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

31 statements  

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

1"""Horizontal rule 

2 

3At least 3 of these characters on a line * - _ 

4""" 

5import logging 

6 

7from ..common.utils import isSpace 

8from .state_block import StateBlock 

9 

10LOGGER = logging.getLogger(__name__) 

11 

12 

13def hr(state: StateBlock, startLine: int, endLine: int, silent: bool): 

14 LOGGER.debug("entering hr: %s, %s, %s, %s", state, startLine, endLine, silent) 

15 

16 pos = state.bMarks[startLine] + state.tShift[startLine] 

17 maximum = state.eMarks[startLine] 

18 

19 # if it's indented more than 3 spaces, it should be a code block 

20 if state.sCount[startLine] - state.blkIndent >= 4: 

21 return False 

22 

23 marker = state.srcCharCode[pos] 

24 pos += 1 

25 

26 # Check hr marker: /* * */ /* - */ /* _ */ 

27 if marker != 0x2A and marker != 0x2D and marker != 0x5F: 

28 return False 

29 

30 # markers can be mixed with spaces, but there should be at least 3 of them 

31 

32 cnt = 1 

33 while pos < maximum: 

34 ch = state.srcCharCode[pos] 

35 pos += 1 

36 if ch != marker and not isSpace(ch): 

37 return False 

38 if ch == marker: 

39 cnt += 1 

40 

41 if cnt < 3: 

42 return False 

43 

44 if silent: 

45 return True 

46 

47 state.line = startLine + 1 

48 

49 token = state.push("hr", "hr", 0) 

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

51 token.markup = chr(marker) * (cnt + 1) 

52 

53 return True