import sys, re, time
# 使用时, python convert.py input.md output.md
def convert(input_name, output_name):
    try:
        with open(input_name, 'r', encoding='utf8') as fr, open(output_name, 'w', encoding='utf8') as fw:
            data = fr.read()
            data = re.sub(r'\${1}(\S.*?)\${1}', r'\(\1\)', data)  # handle $latex$
            data = re.sub(r'\${2}(\S.*?)\${2}', r'\(\1\)', data)  # handle $$latex$$
            data = re.sub(r'(?ms)^(\$\$)(.*?)^\1', r'\(\2\)', data)  # handle $$...$$ on separate lines
            fw.write(data)

        time.sleep(0.5)
        print('Sucess!')
    except FileNotFoundError as e:
        print(e)

if __name__ == "__main__":
    convert(sys.argv[1], sys.argv[2])
打赏作者

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

CAPTCHA