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

23 statements  

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

1# Proceess '\n' 

2import re 

3 

4from ..common.utils import charCodeAt, isSpace 

5from .state_inline import StateInline 

6 

7endSpace = re.compile(r" +$") 

8 

9 

10def newline(state: StateInline, silent: bool): 

11 pos = state.pos 

12 

13 # /* \n */ 

14 if state.srcCharCode[pos] != 0x0A: 

15 return False 

16 

17 pmax = len(state.pending) - 1 

18 maximum = state.posMax 

19 

20 # ' \n' -> hardbreak 

21 # Lookup in pending chars is bad practice! Don't copy to other rules! 

22 # Pending string is stored in concat mode, indexed lookups will cause 

23 # conversion to flat mode. 

24 if not silent: 

25 if pmax >= 0 and charCodeAt(state.pending, pmax) == 0x20: 

26 if pmax >= 1 and charCodeAt(state.pending, pmax - 1) == 0x20: 

27 state.pending = endSpace.sub("", state.pending) 

28 state.push("hardbreak", "br", 0) 

29 else: 

30 state.pending = state.pending[:-1] 

31 state.push("softbreak", "br", 0) 

32 

33 else: 

34 state.push("softbreak", "br", 0) 

35 

36 pos += 1 

37 

38 # skip heading spaces for next line 

39 while pos < maximum and isSpace(state.srcCharCode[pos]): 

40 pos += 1 

41 

42 state.pos = pos 

43 return True