def to_html(cls, kb_entry): r = kb_entry.body.replace("\r", "") parsed = parseString(title=kb_entry.subject, raw=r, wikidb=cls.NOCDB(kb_entry)) preprocess(parsed) xhtml = MWXHTMLWriter() xhtml.writeBook(parsed) block = ET.tostring(xhtml.xmlbody) return block
def getXHTML(wikitext): db = DummyDB() r = parseString(title="test", raw=wikitext, wikidb=db) preprocess(r) show(sys.stdout, r) dbw = MWXHTMLWriter() dbw.writeBook(r) return dbw.asstring()
def getXHTML(wikitext): db = DummyDB() r = parseString(title="", raw=wikitext, wikidb=db) preprocess(r) dbw = MWXHTMLWriter() with SuppressOutput(): dbw.writeBook(r) return dbw.asstring()
def getXHTML(wikitext, title, language): db = DummyDB() db.normalize_and_get_page = noop r = parseString(title=title, raw=wikitext, wikidb=db, lang=language) if not r: return None preprocess(r) removeLangLinks(r) dbw = MWXHTMLWriter() dbw.writeBook(r) return dbw.asstring()
def getXHTML(wikitext, title, language): db = DummyDB() db.normalize_and_get_page = noop r = parseString(title=title, raw=wikitext, wikidb=db, lang=language) if not r: return None preprocess(r) removeLangLinks(r) dbw = MWXHTMLWriter() dbw.writeBook(r) return dbw.asstring()
def to_html(cls, kb_entry): from mwlib.uparser import parseString from mwlib.xhtmlwriter import MWXHTMLWriter, preprocess try: import xml.etree.ElementTree as ET except: from elementtree import ElementTree as ET r = kb_entry.body.replace("\r", "") parsed = parseString(title=kb_entry.subject, raw=r, wikidb=cls.NOCDB(kb_entry)) preprocess(parsed) xhtml = MWXHTMLWriter() xhtml.writeBook(parsed) block = ET.tostring(xhtml.xmlbody) return block
def run(self): raw = u'\n'.join(self.content) # empty wikidb db = DummyDB() # run parser and pre-processors parsed = parseString(title='Export', raw=raw, wikidb=db) preprocess(parsed) # write XHTML xhtml = MWXHTMLWriter() xhtml.writeBook(parsed) # remove the H1 heading (title) from the document article = xhtml.xmlbody.getchildren()[0] article.remove(article.getchildren()[0]) # remove caption # render to string block = ET.tostring(xhtml.xmlbody) return [nodes.raw('', block, format='html')]