Refactor TextEditor to handle block flags in text

This commit is contained in:
bobo 2024-06-18 18:17:57 +08:00
parent 060900a86c
commit df15fba131

View File

@ -209,11 +209,11 @@ class TextEditor(Widget):
def _handle_block_flag(self, text: str):
"""convert \\ to \\, and ` to \\`"""
return text.replace("\\", "\\\\").replace("`", "\\`")
return text.replace("```", "\\`\\`\\`") if text else text
def _remove_block_flag(self, text: str):
"""convert \\ to \\, and \\` to `"""
return text.replace("\\`", "`").replace("\\\\", "\\")
return text.replace("\\`\\`\\`", "```") if text else text
@property
def new_text(self) -> Optional[str]: