def mark(text, args, Mark, extra_cli_args, *a):
    if extra_cli_args and extra_cli_args[0] not in button_map:
        print(f"The key `{extra_cli_args[0]}` is unknown.")
        print(f"You must specify one of: {', '.join(button_map.keys())}")
        return
    if args.type == "emoji" or args.type == "emoji_char_and_name":
        import demoji

        if demoji.last_downloaded_timestamp() is None:
            demoji.download_codes()
        demoji.set_emoji_pattern()
        if args.type == "emoji":
            regex = demoji._EMOJI_PAT
        else:
            emoji_name_pattern = r":[a-z0-9_+-]+:"
            regex = re.compile(r"{}|{}".format(demoji._EMOJI_PAT.pattern,
                                               emoji_name_pattern))
        args.minimum_match_length = 1
    else:
        pattern, _ = functions_for(args)
        regex = re.compile(pattern)
    for idx, (s, e, _) in enumerate(
            regex_finditer(regex, args.minimum_match_length, text)):
        lines = text[:s].split("\n")
        y = len(lines) - 1
        x = wcswidth(lines[-1])
        mark_text = text[s:e].replace("\n", "").replace("\0", "")
        yield Mark(idx, s, e, mark_text, {"x": x, "y": y})
Example #2
0
def start():
    try:
        demoji.set_emoji_pattern()
    except IOError:
        demoji.download_codes()
    if len(sys.argv) <= 1:
        print("No program to run")
        return
    with open(sys.argv[1], encoding="UTF-8") as file:
        parameters = []
        if len(sys.argv) > 2:
            parameters = sys.argv[2:]
        text = file.read()
        interp.run(text, parameters)
Example #3
0
def contains_emoji(s: str) -> bool:
    try:
        demoji.set_emoji_pattern()
    except IOError:
        demoji.download_codes()
    return bool(demoji.findall_list(s, desc=False))
Example #4
0
def test_set_emoji_pattern_no_json_raises():
    if os.path.isfile(demoji.CACHEPATH):
        os.remove(demoji.CACHEPATH)
    with pytest.raises(IOError):
        demoji.set_emoji_pattern()
    assert demoji.last_downloaded_timestamp() is None
Example #5
0
import re

import demoji
import dispy_markdown as md
import pendulum

from api.emoji import EMOJI_LIST, UNICODE_LIST

if not demoji.last_downloaded_timestamp() or pendulum.now() > \
        (pendulum.instance(demoji.last_downloaded_timestamp()).add(days=7)):
    demoji.download_codes()

demoji.set_emoji_pattern()
UNICODE_EMOJI_PAT = demoji._EMOJI_PAT.pattern
jumbo_pat = re.compile(fr'<a?:.*?:\d*>|:[\wñ+-]+:|{UNICODE_EMOJI_PAT}')


class BlockQuote(md.classes['block_quote']):

    @staticmethod
    def html(node, output, state):
        return md.html_tag(
            'div', md.html_tag(
                'div', '', {'class': 'blockquoteDivider-2hH8H6'}, state
            ) + md.html_tag(
                'blockquote', output(node['content'], state)
            ), {'class': 'blockquoteContainer-U5TVEi'}, state
        )


class CodeBlock(md.classes['code_block']):