Skip to content

Instantly share code, notes, and snippets.

@Kwpolska
Last active August 29, 2015 14:23
Show Gist options
  • Save Kwpolska/f86d4f7dd696bcd9198c to your computer and use it in GitHub Desktop.
Save Kwpolska/f86d4f7dd696bcd9198c to your computer and use it in GitHub Desktop.
Markdown document parser (via #python@freenode)
#!/usr/bin/env python3
import re
data = """# Foo
Print a string.
```sh
echo "foo"
```
Delete a file.
```sh
rm the_file.txt
```
Really delete a file.
```sh
rm -f the_file.txt
```"""
pattern = '\n(.*?)\n\n```sh\n(.*?)```'
raw = re.findall(pattern, data, re.DOTALL)
outdict = {k.strip(): v.strip() for k, v in raw}
print(outdict)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment