Created
July 18, 2013 03:34
-
-
Save Ceasar/6026527 to your computer and use it in GitHub Desktop.
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
""" | |
Convert markdown files containing Python code into working Python files. | |
Usage: python md2.py [markdownfile] | |
Example: | |
Flask is Fun | |
============ | |
from flask import Flask | |
app = Flask(__name__) | |
@app.route("/") | |
def hello(): | |
return "Hello World!" | |
if __name__ == "__main__": | |
app.run() | |
Interested? | |
=========== | |
- [Download latest release](http://pypi.python.org/packages/source/F/Flask/Flask-0.10.tar.gz) (0.10) | |
- [Fork it on Github](https://github.com/mitsuhiko/flask) | |
Becomes: | |
# Flask is Fun | |
# ============ | |
from flask import Flask | |
app = Flask(__name__) | |
@app.route("/") | |
def hello(): | |
return "Hello World!" | |
if __name__ == "__main__": | |
app.run() | |
# Interested? | |
# =========== | |
# - [Download latest release](http://pypi.python.org/packages/source/F/Flask/Flask-0.10.tar.gz) (0.10) | |
# - [Fork it on Github](https://github.com/mitsuhiko/flask) | |
""" | |
import sys | |
TAB_WIDTH = 4 | |
INDENT = ' ' * TAB_WIDTH | |
if __name__ == "__main__": | |
with open(sys.argv[1]) as f: | |
for line in f: | |
if not line.strip(): | |
print "" | |
elif line.startswith(INDENT): | |
print line[TAB_WIDTH:].rstrip() | |
else: | |
print "# %s" % line.rstrip() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment