#!/usr/bin/env python #--!-- coding: utf8 --!-- from qt import * from enums import * from functions import * from exporter.basic import basicExporter class htmlExporter(basicExporter): requires = ["filename"] def __init__(self): pass def doCompile(self, filename): mw = mainWindow() root = mw.mdlOutline.rootItem html = "" def appendItem(item): if item.isFolder(): html = "" title = "{t}\n".format( l = str(item.level() + 1), t = item.title()) html += title for c in item.children(): html += appendItem(c) return html else: text = self.formatText(item.text(), item.type()) return text for c in root.children(): html += appendItem(c) template = """ {TITLE} {BODY} """ f = open(filename, "w") f.write(template.format( TITLE="FIXME", BODY=html)) def formatText(self, text, _type): if not text: return text if _type == "t2t": text = self.runT2T(text) elif _type == "txt": text = text.replace("\n", "
") elif _type == "html": # keep only body text = self.htmlBody(text) return text + "
"