Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/markdown_it/rules_block/hr.py: 94%
34 statements
« prev ^ index » next coverage.py v7.2.1, created at 2023-03-14 06:12 +0000
« prev ^ index » next coverage.py v7.2.1, created at 2023-03-14 06:12 +0000
1"""Horizontal rule
3At least 3 of these characters on a line * - _
4"""
5import logging
7from ..common.utils import isSpace
8from .state_block import StateBlock
10LOGGER = logging.getLogger(__name__)
13def hr(state: StateBlock, startLine: int, endLine: int, silent: bool):
14 LOGGER.debug("entering hr: %s, %s, %s, %s", state, startLine, endLine, silent)
16 pos = state.bMarks[startLine] + state.tShift[startLine]
17 maximum = state.eMarks[startLine]
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
23 try:
24 marker = state.srcCharCode[pos]
25 except IndexError:
26 return False
27 pos += 1
29 # Check hr marker: /* * */ /* - */ /* _ */
30 if marker != 0x2A and marker != 0x2D and marker != 0x5F:
31 return False
33 # markers can be mixed with spaces, but there should be at least 3 of them
35 cnt = 1
36 while pos < maximum:
37 ch = state.srcCharCode[pos]
38 pos += 1
39 if ch != marker and not isSpace(ch):
40 return False
41 if ch == marker:
42 cnt += 1
44 if cnt < 3:
45 return False
47 if silent:
48 return True
50 state.line = startLine + 1
52 token = state.push("hr", "hr", 0)
53 token.map = [startLine, state.line]
54 token.markup = chr(marker) * (cnt + 1)
56 return True