def post_tex(self, tex, name): # 返回的 ID 是 int j = { 'tex': tex } if URL_CHAPTER.endswith('.mkiv'): j['html'] = html(buf = tex) ID = self.get_id_by_name(name) if ID: method = "PUT" uri = URL_PUT % (SERVER, ID) else: method = "POST" uri = URL_POST % SERVER headers = {'Content-Type': "application/json"}; res = requests.request(method, uri, headers=headers, data=json.dumps(j)) return int(res.text)
def handle(): if Config.o == "-": f = sys.stdout else: f = codecs.open(Config.o, "w", "utf8") if Config.js: f.write("<script>\n") f.write(open(Config.js).read()) f.write("\n</script>\n") if Config.css: f.write("<style>\n") f.write(open(Config.css).read()) f.write("\n</style>\n") if Config.type == "markdown": res = textohtml.markdown(path=Config.input) else: res = textohtml.html(path=Config.input) f.write(res) f.close()
def GET(self): qindex = self.query.get("index") tp = self.query.get("type", 'HTML').lower() if qindex and qindex == str(self.index) and tp == self.request_type: return [self.index, '', tp] self.request_type = tp data = self.data if tp == 'html': try: data = html(buf = self.data) except: data = "<pre>%s</pre>" % traceback.format_exc() elif tp == 'markdown': try: data = markdown(buf = self.data) except: data = "<pre>%s</pre>" % traceback.format_exc() return [self.index, data, tp]