-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Smartquotes, typographic replacements and plain text links can now be escaped with backslash (e.g. `\(c)` or `google\.com` are no longer replaced). Implements upstream: markdown-it/markdown-it@75037c6 Breaking: - `text_collapse` rule is renamed to `fragments_join` - Added a new token type `text_special` to store escaped characters, same as `text` but unaffected by replacement plugins (smartquotes, typographer, linkifier, etc.). - Added a new rule `text_join` in `core` ruler. Text replacement plugins may choose to insert themselves before it.
- Loading branch information
1 parent
500e69e
commit 05c6654
Showing
13 changed files
with
170 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"""Join raw text tokens with the rest of the text | ||
This is set as a separate rule to provide an opportunity for plugins | ||
to run text replacements after text join, but before escape join. | ||
For example, `\\:)` shouldn't be replaced with an emoji. | ||
""" | ||
from __future__ import annotations | ||
|
||
from ..token import Token | ||
from .state_core import StateCore | ||
|
||
|
||
def text_join(state: StateCore) -> None: | ||
"""Join raw text for escape sequences (`text_special`) tokens with the rest of the text""" | ||
|
||
for inline_token in state.tokens[:]: | ||
|
||
if inline_token.type != 'inline': | ||
continue | ||
|
||
# convert text_special to text and join all adjacent text nodes | ||
new_tokens: list[Token] = [] | ||
for child_token in (inline_token.children or []): | ||
if child_token.type == 'text_special': | ||
child_token.type = 'text' | ||
if child_token.type == 'text' and new_tokens and new_tokens[-1].type == 'text': | ||
new_tokens[-1].content += child_token.content | ||
else: | ||
new_tokens.append(child_token) | ||
inline_token.children = new_tokens |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
markdown_it/rules_inline/text_collapse.py → markdown_it/rules_inline/fragments_join.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.