manuskript/manuskript/exporter/basic.py

30 lines
787 B
Python
Raw Normal View History

2015-07-01 23:14:03 +12:00
#!/usr/bin/env python
2016-02-07 00:34:22 +13:00
# --!-- coding: utf8 --!--
2015-07-02 00:51:43 +12:00
import re
2016-02-07 00:34:22 +13:00
import subprocess
2015-07-01 23:14:03 +12:00
class basicExporter():
def __init__(self):
pass
2016-02-07 00:34:22 +13:00
2015-07-01 23:14:03 +12:00
def runT2T(self, text, target="html"):
2016-02-07 00:34:22 +13:00
2015-07-01 23:14:03 +12:00
cmdl = ['txt2tags', '-t', target, '--enc=utf-8', '--no-headers', '-o', '-', '-']
2016-02-07 00:34:22 +13:00
2015-07-01 23:14:03 +12:00
cmd = subprocess.Popen(('echo', text), stdout=subprocess.PIPE)
try:
2016-02-07 00:34:22 +13:00
output = subprocess.check_output(cmdl, stdin=cmd.stdout, stderr=subprocess.STDOUT) # , cwd="/tmp"
2015-07-01 23:14:03 +12:00
except subprocess.CalledProcessError as e:
print("Error!")
return text
cmd.wait()
2016-02-07 00:34:22 +13:00
2015-07-01 23:14:03 +12:00
return output.decode("utf-8")
2016-02-07 00:34:22 +13:00
2015-07-02 00:51:43 +12:00
def htmlBody(self, text):
text = text.replace("\n", "")
text = re.sub(r".*<body[^>]*?>(.*)</body>.*", "\\1", text)
return text