Last active
June 4, 2019 04:17
-
-
Save pillyshi/8a8e60e0c7624e67b0cf3e8b3a94f6cb to your computer and use it in GitHub Desktop.
Convert markdown to the text for wordpress web editor.
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
import argparse | |
import re | |
def get_args(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--in-path', type=str) | |
return parser.parse_args() | |
def convert(text): | |
text = re.sub(r'\\', r'\\\\', text) | |
text = re.sub(r'_', r'\\_', text) | |
text = re.sub(r'\$(.+?)\$', r'[latex]\1[/latex]', text) | |
text = re.sub(r'\$\$([\s\S]+?)\$\$', r'[latex display="true"]\1[/latex]', text) | |
text = text.replace('\n', '') | |
return text | |
def main(args): | |
with open(args.in_path) as f: | |
text = f.read() | |
text = '\n\n'.join(convert(t) for t in text.split('\n\n')) | |
print(text) | |
if __name__ == "__main__": | |
args = get_args() | |
main(args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script supports
wp-katex
plugin. Equations written in latex will be converted as follows:$ ~ $
=>[latex] ~ [/latex]
$$ ~ $$
=>[latex display="true"] ~ [/latex]