From b2f92988173414a8da8dc1a87b1141621d742901 Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Tue, 12 Apr 2022 00:55:43 -0400 Subject: [PATCH] Remove some apparently unused inbound formatting --- .../formatter/from_kakaotalk.py | 54 +------------------ 1 file changed, 1 insertion(+), 53 deletions(-) diff --git a/matrix_appservice_kakaotalk/formatter/from_kakaotalk.py b/matrix_appservice_kakaotalk/formatter/from_kakaotalk.py index ffb0a75..e1536c5 100644 --- a/matrix_appservice_kakaotalk/formatter/from_kakaotalk.py +++ b/matrix_appservice_kakaotalk/formatter/from_kakaotalk.py @@ -24,61 +24,9 @@ from ..kt.types.chat.attachment.mention import MentionStruct from .. import puppet as pu, user as u -_START = r"^|\s" -_END = r"$|\s" -_TEXT_NO_SURROUNDING_SPACE = r"(?:[^\s].*?[^\s])|[^\s]" -COMMON_REGEX = re.compile(rf"({_START})([_~*])({_TEXT_NO_SURROUNDING_SPACE})\2({_END})") -INLINE_CODE_REGEX = re.compile(rf"({_START})(`)(.+?)`({_END})") + MENTION_REGEX = re.compile(r"@(\d+)\u2063(.+?)\u2063") -tags = {"_": "em", "*": "strong", "~": "del", "`": "code"} - - -def _handle_match(html: str, match: Match, nested: bool) -> tuple[str, int]: - start, end = match.start(), match.end() - prefix, sigil, text, suffix = match.groups() - if nested: - text = _convert_formatting(text) - tag = tags[sigil] - # We don't want to include the whitespace suffix length, as that could be used as the - # whitespace prefix right after this formatting block. - pos = start + len(prefix) + (2 * len(tag) + 5) + len(text) - html = f"{html[:start]}{prefix}<{tag}>{text}{suffix}{html[end:]}" - return html, pos - - -def _convert_formatting(html: str) -> str: - pos = 0 - while pos < len(html): - i_match = INLINE_CODE_REGEX.search(html, pos) - c_match = COMMON_REGEX.search(html, pos) - if i_match and c_match: - match = min(i_match, c_match, key=lambda match: match.start()) - else: - match = i_match or c_match - - if match: - html, pos = _handle_match(html, match, nested=match != i_match) - else: - break - return html - - -def _handle_blockquote(output: list[str], blockquote: bool, line: str) -> tuple[bool, str]: - if not blockquote and line.startswith("> "): - line = line[len("> ") :] - output.append("
") - blockquote = True - elif blockquote: - if line.startswith(">"): - line = line[len(">") :] - if line.startswith(" "): - line = line[1:] - else: - output.append("
") - blockquote = False - return blockquote, line - async def kakaotalk_to_matrix(msg: str | None, mentions: list[MentionStruct] | None) -> TextMessageEventContent: # TODO Shouts