STDIN conversion is working.

while preparing hybrideditor for pzi server
master
Castro0o 7 years ago
parent 45f151af79
commit 152b4896f2

2
.gitignore vendored

@ -1,2 +0,0 @@
*.pyc
*~

@ -20,6 +20,14 @@ http://localhost:8000/cgi-bin/start.cgi
or
http://localhost:8000/cgi-bin/select.cgi
## install using cgi-bin
```bash
mkdir /var/www/cgi-bin/hybrideditor/
ln cgi-bin/* /var/www/cgi-bin/hybrideditor/
chmod +x cgi-bin/
```
## License
This software is released under a [GPLv3 license](http://www.gnu.org/copyleft/gpl.html). See LICENSE.
This software is released under a [GPLv3 license](http://www.gnu.org/copyleft/gpl.html). See LICENSE.

@ -1,7 +1,7 @@
#!/usr/bin/env python
import cgitb; cgitb.enable()
import cgi, os, sys, subprocess
import cgi, os, sys, subprocess, shlex
from tempfile import NamedTemporaryFile as NTF
from settings import PANDOC
@ -33,6 +33,13 @@ def guess_format_from_filename (fn):
return "docx"
return "txt"
def print_template(txt):
print "Content-type: text/html;charset=utf-8"
print
print txt
if method == "POST":
fs = cgi.FieldStorage()
from_format = fs.getvalue("from")
@ -57,8 +64,7 @@ if method == "POST":
if from_format == None:
from_format = guess_format_from_filename(f.filename)
# tmp = NTF(delete=False)
tmp = open('pandoc.tmp','wb')
tmp = NTF(delete=False)
bytes = 0
while True:
data = f.file.read()
@ -77,10 +83,7 @@ if method == "POST":
print
# p = subprocess.check_output('pandoc --from {0} --to {1} "{2}"'.format(ffrom, to, tmp.name), shell=True, stderr=subprocess.STDOUT)
# print p
if to_format is 'icml':
p = subprocess.Popen([PANDOC, '--from', 'docx', '--to', to_format,'-s', '/home/andre/public_html/oooooooooo.io/cgi-bin/pandoc.tmp'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
else:
p = subprocess.Popen([PANDOC, '--from', 'docx', '--to', to_format, '/home/andre/public_html/oooooooooo.io/cgi-bin/pandoc.tmp', '--atx-headers'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p = subprocess.Popen([PANDOC, '--from', from_format, '--to', to_format, tmp.name], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
print out
@ -90,29 +93,31 @@ if method == "POST":
print
print u"<span style='font-family:monospace'>An error occurred, pandoc said: {0}</span>".format(e.output).format("utf-8")
# tmp.unlink(tmp.name)
tmp.unlink(tmp.name)
###################################
# FORM/TEXT INPUT
###################################
else:
text = fs.getvalue("text")
if from_format and to_format:
if from_format and to_format:
try:
print "Content-type: {0}".format(to_type['mime'])
if download:
print "Content-Disposition: attachment;filename=\"hype_conversion.{0}\"".format(to_type['ext'])
print
# p = subprocess.check_output('pandoc --from {0} --to {1} "{2}"'.format(ffrom, to, tmp.name), shell=True, stderr=subprocess.STDOUT)
# print p
#p = subprocess.check_output('echo "{2}"|pandoc --from {0} --to {1} '.format(from_format, to_format, '#foo'), shell=True, stderr=subprocess.STDOUT)
#print p
cmd = "{} --from {} --to {}".format(PANDOC, from_format, to_format)
cmd_list = shlex.split( cmd )
if to_format == 'icml':
p = subprocess.Popen([PANDOC, '--from', from_format, '--to', to_format , '-s'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
else:
p = subprocess.Popen([PANDOC, '--from', from_format, '--to', to_format, '--atx-headers' ], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p = subprocess.Popen(cmd_list, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate(text)
print out
print cmd+' '+ out
except subprocess.CalledProcessError, e:
print "Content-type: text/html;charset=utf-8"
@ -125,22 +130,22 @@ if method == "POST":
print u"<span style='font-family:monospace'>Format unspecified</span>".encode("utf-8")
sys.exit(0)
print "Content-type: text/html;charset=utf-8"
print
print """<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
</head>
<body>
<form enctype="multipart/form-data" action="" method="post">
<p>Convert: <input type="file" name="file"></p>
to: <select name="to">
<option>markdown</option>
<option>html</option>
</select>
<p><input type="submit" value="OK"></p>
</form>
</body></html>
"""
'''
'''
# print """<!DOCTYPE html>
# <html>
# <head>
# <meta charset="utf-8" />
# </head>
# <body>
# <form enctype="multipart/form-data" action="" method="post">
# <p>Convert: <input type="file" name="file"></p>
# to: <select name="to">
# <option>markdown</option>
# <option>html</option>
# </select>
# <p><input type="submit" value="OK"></p>
# </form>
# </body></html>
# """

Binary file not shown.

@ -4,6 +4,6 @@ MAKE = "make"
MAKEFILE = None
PROJECT_PATH = "./projects"
PROJECT_URL = "/projects/" # must end with /
EDITOR_URL = "/cgi-bin/hype.cgi"
EDITOR_URL = "/cgi-bin/pandoc-cgi/hype.cgi"
SAMPLE_PROJECT_PATH = "projects/sample"

@ -16,12 +16,12 @@
<span class="label">write markdown</span> /
<button id="openbutton">import .docx</button>
<div id="openmenu">
<form id="dropzone" action="/cgi-bin/pandoc.cgi" class="dropzone">
<form id="dropzone" action="/cgi-bin/hybrideditor/pandoc.cgi" class="dropzone">
<div class="fallback">
<input name="file" type="file" />
</div>
</form>
<!-- <form id="sideload" style="margin-top: 5px" action="/cgi-bin/pandoc.cgi">
<!-- <form id="sideload" style="margin-top: 5px" action="/cgi-bin/hybrideditor/pandoc.cgi">
<label for="importurl">Upload from URL:</label><br />
<input id="importurl" name="url" type="text" />
<input type="submit" name="_submit" value="import" />
@ -37,7 +37,7 @@
<div id="preview" class="right">
<div class="header">
<div class="header-center">
<form id="previewform" method="post" action="/cgi-bin/pandoc.cgi" target="previewiframe">
<form id="previewform" method="post" action="/cgi-bin/hybrideditor/pandoc.cgi" target="previewiframe">
<input type="hidden" name="text" id="previewformtext" />
<input type="hidden" name="from" value="markdown" />
<select id="formatselect" name="to" onchange="this.form.submit()">

@ -53,4 +53,5 @@ editor.setHighlightActiveLine(false);
editor.setShowInvisibles(false);
editor.getSession().setMode("ace/mode/markdown");
editor.getSession().setUseWrapMode(true);
editor.setValue(""); // reset the editor

Loading…
Cancel
Save