Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/markdown_it/rules_inline/newline.py: 100%
24 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:15 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:15 +0000
1"""Proceess '\n'."""
2from ..common.utils import charStrAt, isStrSpace
3from .state_inline import StateInline
6def newline(state: StateInline, silent: bool) -> bool:
7 pos = state.pos
9 if state.src[pos] != "\n":
10 return False
12 pmax = len(state.pending) - 1
13 maximum = state.posMax
15 # ' \n' -> hardbreak
16 # Lookup in pending chars is bad practice! Don't copy to other rules!
17 # Pending string is stored in concat mode, indexed lookups will cause
18 # conversion to flat mode.
19 if not silent:
20 if pmax >= 0 and charStrAt(state.pending, pmax) == " ":
21 if pmax >= 1 and charStrAt(state.pending, pmax - 1) == " ":
22 # Find whitespaces tail of pending chars.
23 ws = pmax - 1
24 while ws >= 1 and charStrAt(state.pending, ws - 1) == " ":
25 ws -= 1
26 state.pending = state.pending[:ws]
28 state.push("hardbreak", "br", 0)
29 else:
30 state.pending = state.pending[:-1]
31 state.push("softbreak", "br", 0)
33 else:
34 state.push("softbreak", "br", 0)
36 pos += 1
38 # skip heading spaces for next line
39 while pos < maximum and isStrSpace(state.src[pos]):
40 pos += 1
42 state.pos = pos
43 return True