diff --git a/.gitignore b/.gitignore deleted file mode 100644 index f3d74a9..0000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*.pyc -*~ diff --git a/README.md b/README.md index aa1618f..fd823f2 100644 --- a/README.md +++ b/README.md @@ -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. \ No newline at end of file +This software is released under a [GPLv3 license](http://www.gnu.org/copyleft/gpl.html). See LICENSE. diff --git a/cgi-bin/pandoc.cgi b/cgi-bin/pandoc.cgi index 31ca8e0..9ea0aee 100755 --- a/cgi-bin/pandoc.cgi +++ b/cgi-bin/pandoc.cgi @@ -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"An error occurred, pandoc said: {0}".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"Format unspecified".encode("utf-8") sys.exit(0) - -print "Content-type: text/html;charset=utf-8" -print -print """ - - - - - -
-

Convert:

-to: -

-
- -""" +''' +''' + +# print """ +# +# +# +# +# +#
+#

Convert:

+# to: +#

+#
+# +# """ diff --git a/cgi-bin/pandoc.tmp b/cgi-bin/pandoc.tmp deleted file mode 100644 index 50d1ee7..0000000 Binary files a/cgi-bin/pandoc.tmp and /dev/null differ diff --git a/cgi-bin/settings.py b/cgi-bin/settings.py index 8f2e2d4..2f3b07d 100644 --- a/cgi-bin/settings.py +++ b/cgi-bin/settings.py @@ -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" diff --git a/fonts/OpenSans-Bold.ttf b/fonts/OpenSans-Bold.ttf old mode 100755 new mode 100644 diff --git a/fonts/OpenSans-BoldItalic.ttf b/fonts/OpenSans-BoldItalic.ttf old mode 100755 new mode 100644 diff --git a/fonts/OpenSans-Italic.ttf b/fonts/OpenSans-Italic.ttf old mode 100755 new mode 100644 diff --git a/fonts/OpenSans-Light.ttf b/fonts/OpenSans-Light.ttf old mode 100755 new mode 100644 diff --git a/fonts/OpenSans-LightItalic.ttf b/fonts/OpenSans-LightItalic.ttf old mode 100755 new mode 100644 diff --git a/fonts/OpenSans-Regular.ttf b/fonts/OpenSans-Regular.ttf old mode 100755 new mode 100644 diff --git a/hybrid.html b/hybrid.html index e10733c..83b010e 100644 --- a/hybrid.html +++ b/hybrid.html @@ -16,12 +16,12 @@ write markdown /
-
+
-