mirror of
https://git.ludikovsky.name/git/mdlive.git
synced 2024-05-16 23:15:28 +02:00
Erste funktionierende Version
This commit is contained in:
commit
24596c944e
24
mdlive.py
Executable file
24
mdlive.py
Executable 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
28
static/index.html
Normal 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>
|
Loading…
Reference in a new issue