# HG changeset patch # User Thierry Florac # Date 1544827304 -3600 # Node ID e13fba68f3633e015a26ba8db21cf54c6fcbecab # Parent 1f4687ad112ec6063ce614acd2523ef7bc09705b Added ReStructuredText and Markdown raw code renderers diff -r 1f4687ad112e -r e13fba68f363 src/pyams_default_theme/component/paragraph/html.py --- a/src/pyams_default_theme/component/paragraph/html.py Fri Dec 14 18:40:02 2018 +0100 +++ b/src/pyams_default_theme/component/paragraph/html.py Fri Dec 14 23:41:44 2018 +0100 @@ -17,16 +17,16 @@ from pyams_content.component.illustration import IIllustration from pyams_content.component.paragraph.interfaces.html import IHTMLParagraph, IRawParagraph from pyams_content.features.renderer.interfaces import IContentRenderer +from pyams_default_theme import _ from pyams_default_theme import library from pyams_default_theme.features.renderer import BaseContentRenderer from pyams_skin.layer import IPyAMSLayer from pyams_template.template import template_config from pyams_utils.adapter import adapter_config, get_annotation_adapter from pyams_utils.fanstatic import ExternalResource +from pyams_utils.interfaces.text import IHTMLRenderer from pyams_utils.pygments import IPygmentsCodeConfiguration, PygmentsCodeRendererSettings, render_source -from pyams_default_theme import _ - # # Raw paragraph default renderer @@ -85,6 +85,46 @@ return '' +@adapter_config(name='rest', context=(IRawParagraph, IPyAMSLayer), provides=IContentRenderer) +@template_config(template='templates/raw-rest.pt', layer=IPyAMSLayer) +class RawParagraphRestRenderer(BaseContentRenderer): + """Raw paragraph ReStructuredText code renderer""" + + label = _("ReStructuredText renderer") + weight = 20 + + i18n_context_attrs = ('title', 'body') + + @property + def source(self): + code = self.body + if code: + renderer = self.request.registry.queryMultiAdapter((code, self.request), IHTMLRenderer, name='rest') + if renderer is not None: + return renderer.render() + return '' + + +@adapter_config(name='markdown', context=(IRawParagraph, IPyAMSLayer), provides=IContentRenderer) +@template_config(template='templates/raw-markdown.pt', layer=IPyAMSLayer) +class RawParagraphMarkdownRenderer(BaseContentRenderer): + """Raw paragraph markdown code renderer""" + + label = _("Markdown renderer") + weight = 30 + + i18n_context_attrs = ('title', 'body') + + @property + def source(self): + code = self.body + if code: + renderer = self.request.registry.queryMultiAdapter((code, self.request), IHTMLRenderer, name='markdown') + if renderer is not None: + return renderer.render() + return '' + + # # HTML paragraph default renderer # diff -r 1f4687ad112e -r e13fba68f363 src/pyams_default_theme/component/paragraph/templates/raw-markdown.pt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_default_theme/component/paragraph/templates/raw-markdown.pt Fri Dec 14 23:41:44 2018 +0100 @@ -0,0 +1,4 @@ +

${view.title}

+ + ${structure:view.source} + diff -r 1f4687ad112e -r e13fba68f363 src/pyams_default_theme/component/paragraph/templates/raw-rest.pt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_default_theme/component/paragraph/templates/raw-rest.pt Fri Dec 14 23:41:44 2018 +0100 @@ -0,0 +1,4 @@ +

${view.title}

+ + ${structure:view.source} +