1.1 --- a/MoinSupport.py Mon Jun 25 00:18:57 2012 +0200
1.2 +++ b/MoinSupport.py Wed Jul 11 00:48:15 2012 +0200
1.3 @@ -563,6 +563,12 @@
1.4
1.5 # Page parsing and formatting of embedded content.
1.6
1.7 +def getPageParserClass(request):
1.8 +
1.9 + "Using 'request', return a parser class for the current page's format."
1.10 +
1.11 + return getParserClass(request, request.page.pi["format"])
1.12 +
1.13 def getParserClass(request, format):
1.14
1.15 """
1.16 @@ -575,6 +581,38 @@
1.17 except wikiutil.PluginMissingError:
1.18 return wikiutil.searchAndImportPlugin(request.cfg, "parser", "plain")
1.19
1.20 +def getFormatterClass(request, format):
1.21 +
1.22 + """
1.23 + Return a formatter class using the 'request' for the given output 'format',
1.24 + returning a plain text formatter if no formatter can be found for the
1.25 + specified 'format'.
1.26 + """
1.27 +
1.28 + try:
1.29 + return wikiutil.searchAndImportPlugin(request.cfg, "formatter", format or "plain")
1.30 + except wikiutil.PluginMissingError:
1.31 + return wikiutil.searchAndImportPlugin(request.cfg, "formatter", "plain")
1.32 +
1.33 +def formatText(text, request, fmt, parser_cls=None):
1.34 +
1.35 + """
1.36 + Format the given 'text' using the specified 'request' and formatter 'fmt'.
1.37 + Suppress line anchors in the output, and fix lists by indicating that a
1.38 + paragraph has already been started.
1.39 + """
1.40 +
1.41 + if not parser_cls:
1.42 + parser_cls = getPageParserClass(request)
1.43 + parser = parser_cls(text, request, line_anchors=False)
1.44 +
1.45 + old_fmt = request.formatter
1.46 + request.formatter = fmt
1.47 + try:
1.48 + return redirectedOutput(request, parser, fmt, inhibit_p=True)
1.49 + finally:
1.50 + request.formatter = old_fmt
1.51 +
1.52 def redirectedOutput(request, parser, fmt, **kw):
1.53
1.54 "A fixed version of the request method of the same name."