Erste funktionierende Version

This commit is contained in:
Peter 2016-05-03 17:27:30 +02:00
commit 24596c944e
Signed by: pludi
GPG Key ID: CFBA360E696EDC99
2 changed files with 52 additions and 0 deletions

24
mdlive.py Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env python3
from flask import Flask, render_template, redirect, url_for, request
import subprocess
import shlex
app = Flask(__name__, static_url_path='')
command = shlex.split('/usr/bin/pandoc -f markdown+footnotes+inline_notes+auto_identifiers -t html5 --smart')
@app.route("/")
def index():
return app.send_static_file('index.html')
@app.route("/parse", methods=['GET', 'POST'])
def parse():
if request.method == 'GET':
return redirect(url_for('index'))
data = request.form['markdown']
proc = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, universal_newlines=True)
return proc.communicate(input=data)
if __name__ == "__main__":
app.debug = True
app.run()

28
static/index.html Normal file
View File

@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<title>Live Markdown</title>
<meta charset="utf-8">
<script src="https://cdn.jsdelivr.net/jquery/2.2.3/jquery.min.js"></script>
</head>
<body>
<div id="input">
<textarea id="markdown" name="markdown" rows="25" cols="80"></textarea>
</div>
<div id="output"></div>
<script>
$('#input').change(
function(){
$.ajax({
url: "http://localhost:5000/parse",
success: function(result) {
$('#output').html(result);
},
data: { markdown: $('#markdown').val() },
type: 'POST'
});
}
);
</script>
</body>
</html>