Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/markdown_it/rules_core/text_join.py: 100%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

16 statements  

1"""Join raw text tokens with the rest of the text 

2 

3This is set as a separate rule to provide an opportunity for plugins 

4to run text replacements after text join, but before escape join. 

5 

6For example, `\\:)` shouldn't be replaced with an emoji. 

7""" 

8 

9from __future__ import annotations 

10 

11from ..token import Token 

12from .state_core import StateCore 

13 

14 

15def text_join(state: StateCore) -> None: 

16 """Join raw text for escape sequences (`text_special`) tokens with the rest of the text""" 

17 

18 for inline_token in state.tokens[:]: 

19 if inline_token.type != "inline": 

20 continue 

21 

22 # convert text_special to text and join all adjacent text nodes 

23 new_tokens: list[Token] = [] 

24 for child_token in inline_token.children or []: 

25 if child_token.type == "text_special": 

26 child_token.type = "text" 

27 if ( 

28 child_token.type == "text" 

29 and new_tokens 

30 and new_tokens[-1].type == "text" 

31 ): 

32 new_tokens[-1].content += child_token.content 

33 else: 

34 new_tokens.append(child_token) 

35 inline_token.children = new_tokens