def parse(story): """ The main workhorse that does nothing but call MoinMoin to do its dirty laundry @param story: A text for conversion @type story: string @returns: formatted string @rtype: string """ s = StringIO() oldstdout = sys.stdout form = None page = Page(None) page.hilite_re = None request = Request() request.user = User() formatter = Formatter(request) formatter.setPage(page) sys.stdout = s Parser(story, request).format(formatter, form) sys.stdout = oldstdout result = s.getvalue() s.close() return result
def parse(body): """Parse body and return html Create a page with body, then parse it and format using html formatter """ assert body is not None request.reset() pg = Page(request, 'ThisPageDoesNotExistsAndWillNeverBeReally') pg.set_raw_body(body) from MoinMoin.formatter.text_html import Formatter pg.formatter = Formatter(request) request.formatter = pg.formatter pg.formatter.setPage(pg) pg.hilite_re = None output = [] # Temporarily replace request.write with custom write function that # write into our output object. def write_output(text, o=output): o.append(text) saved_write = request.write request.write = write_output try: Parser(body, request).format(pg.formatter) finally: request.write = saved_write return ''.join(output)
def parse15(story): """ The main workhorse that does nothing but call MoinMoin to do its dirty laundry. This version compatible with MoinMoin 1.5 @param story: A text for conversion @type story: string @returns: formatted string @rtype: string """ s = StringIO() oldstdout = sys.stdout form = None request = RequestCLI() #request.user = User() page = Page(request, '') page.hilite_re = None formatter = Formatter(request) formatter.setPage(page) sys.stdout = s Parser(story, request).format(formatter) sys.stdout = oldstdout result = s.getvalue() s.close() return result
def parse(self, body): """Parse body and return html Create a page with body, then parse it and format using html formatter """ request = self.request assert body is not None request.reset() page = Page(request, PAGENAME) page.hilite_re = None page.set_raw_body(body) formatter = HtmlFormatter(request) formatter.setPage(page) page.formatter = formatter request.formatter = formatter parser = WikiParser(body, request, line_anchors=False) formatter.startContent('') # needed for _include_stack init output = request.redirectedOutput(parser.format, formatter) formatter.endContent('') return output
def parse(self, body): """Parse body and return html Create a page with body, then parse it and format using html formatter """ request = self.request assert body is not None request.reset() page = Page(request, PAGENAME) page.hilite_re = None page.set_raw_body(body) formatter = HtmlFormatter(request) formatter.setPage(page) page.formatter = formatter request.formatter = formatter parser = WikiParser(body, request, line_anchors=False) formatter.startContent("") # needed for _include_stack init output = request.redirectedOutput(parser.format, formatter) formatter.endContent("") return output
def parse(self, body): """Parse body and return html Create a page with body, then parse it and format using html formatter """ assert body is not None self.request.reset() page = Page(self.request, 'ThisPageDoesNotExistsAndWillNeverBeReally') page.set_raw_body(body) from MoinMoin.formatter.text_html import Formatter page.formatter = Formatter(self.request) self.request.formatter = page.formatter page.formatter.setPage(page) page.hilite_re = None output = StringIO() saved_write = self.request.write self.request.write = output.write try: Parser(body, self.request).format(page.formatter) finally: self.request.write = saved_write return output.getvalue()