Skip to content

Instantly share code, notes, and snippets.

@Ceasar
Created July 18, 2013 03:34
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Ceasar/6026527 to your computer and use it in GitHub Desktop.
"""
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