Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/markdown_it/rules_core/text_join.py: 100%
15 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"""Join raw text tokens with the rest of the text
3This is set as a separate rule to provide an opportunity for plugins
4to run text replacements after text join, but before escape join.
6For example, `\\:)` shouldn't be replaced with an emoji.
7"""
8from __future__ import annotations
10from ..token import Token
11from .state_core import StateCore
14def text_join(state: StateCore) -> None:
15 """Join raw text for escape sequences (`text_special`) tokens with the rest of the text"""
17 for inline_token in state.tokens[:]:
18 if inline_token.type != "inline":
19 continue
21 # convert text_special to text and join all adjacent text nodes
22 new_tokens: list[Token] = []
23 for child_token in inline_token.children or []:
24 if child_token.type == "text_special":
25 child_token.type = "text"
26 if (
27 child_token.type == "text"
28 and new_tokens
29 and new_tokens[-1].type == "text"
30 ):
31 new_tokens[-1].content += child_token.content
32 else:
33 new_tokens.append(child_token)
34 inline_token.children = new_tokens