Files
markdownplease.com/service.py
T
Gilberto Gonçalves 3ce06e39bf Now this project features a mini paranoid browser
* Changed the names of some functions;
* Bootstrapped it up;
* Added the capability of being a mini-browser by converting the
markdown to HTML by default via the html app, if you curl it, it
should give you the markdown as always.
* Some prettification of the templates
2013-11-18 22:18:37 +00:00

43 lines
994 B
Python

# -*- coding: utf-8 -*-
from flask import Flask, request, render_template, Markup
from converter import get_readable_content_from_url
from markdown import markdown
app = Flask(__name__)
def _markdown_to_html(text):
return Markup(markdown(text))
@app.route('/')
def fuck_gpl3():
url = request.args.get('url')
type = request.args.get('type', 'markdown')
content = get_readable_content_from_url(url)
print url
if type == 'html':
print url
markdown_url_contents = _markdown_to_html(content)
return render_template(
'index.html',
converted_url_contents=markdown_url_contents,
page_url=url,
)
else:
if url:
if content:
return content, 200, {'Content-Type': 'text/x-markdown; charset=UTF-8'}
else:
return '404 Not Found', 404
else:
return render_template('index.html')
if __name__ == '__main__':
app.run()