Last active
March 9, 2023 13:49
-
-
Save mw3i/1778e4d89340dde613689bd8a20baf00 to your computer and use it in GitHub Desktop.
Hastly thrown together way of executing all python codeblocks in a markdown file
This file contains hidden or 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
#!/usr/local/bin/python3 | |
''' | |
This site is very useful for regex testing: https://pythex.org/ | |
''' | |
import re, argparse | |
args = argparse.ArgumentParser(description = 'Execute all the blocks in a markdown script') | |
args.add_argument('file_path', help = 'File you want to execute') | |
args = args.parse_args() | |
with open(args.file_path, 'r') as file: | |
data = re.findall(r"(\`{3}[\w|\W]+?\`{3})", file.read()) | |
for block in data: | |
block = re.sub(r"(?m)^\```(.*)$", "", block) | |
exec(block) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment