1"""Horizontal rule
2
3At least 3 of these characters on a line * - _
4"""
5import logging
6
7from ..common.utils import isStrSpace
8from .state_block import StateBlock
9
10LOGGER = logging.getLogger(__name__)
11
12
13def hr(state: StateBlock, startLine: int, endLine: int, silent: bool) -> 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 state.is_code_block(startLine):
20 return False
21
22 try:
23 marker = state.src[pos]
24 except IndexError:
25 return False
26 pos += 1
27
28 # Check hr marker
29 if marker not in ("*", "-", "_"):
30 return False
31
32 # markers can be mixed with spaces, but there should be at least 3 of them
33
34 cnt = 1
35 while pos < maximum:
36 ch = state.src[pos]
37 pos += 1
38 if ch != marker and not isStrSpace(ch):
39 return False
40 if ch == marker:
41 cnt += 1
42
43 if cnt < 3:
44 return False
45
46 if silent:
47 return True
48
49 state.line = startLine + 1
50
51 token = state.push("hr", "hr", 0)
52 token.map = [startLine, state.line]
53 token.markup = marker * (cnt + 1)
54
55 return True