diff --git a/configure.zcml b/configure.zcml index 701176b..a29445a 100644 --- a/configure.zcml +++ b/configure.zcml @@ -1,6 +1,7 @@ @@ -478,6 +479,19 @@ component="loops.view.NodeTypeSourceList" name="loops.nodeTypeSource" /> + + + + + + diff --git a/interfaces.py b/interfaces.py index cc82fde..ccb4c44 100644 --- a/interfaces.py +++ b/interfaces.py @@ -402,7 +402,7 @@ class IDocumentSchema(IResourceSchema): contentType = schema.Choice( title=_(u'Content Type'), description=_(u'Content type (format) of the data field'), - values=('text/restructured', 'text/structured', 'text/html', + values=('text/markdown', 'text/restructured', 'text/structured', 'text/html', 'text/plain', 'text/xml', 'text/css'), default='text/restructured', required=True) @@ -968,5 +968,3 @@ class IViewConfiguratorSchema(Interface): value_type=schema.TextLine(), default=[], required=False) - - diff --git a/util.py b/util.py index 6ba91a9..1421c11 100644 --- a/util.py +++ b/util.py @@ -21,12 +21,17 @@ Utility functions. """ import os +from zope.publisher.browser import BrowserView from zope import component -from zope.interface import directlyProvides, directlyProvidedBy +from zope.interface import directlyProvides, directlyProvidedBy, implements from zope.intid.interfaces import IIntIds from zope.i18nmessageid import MessageFactory +from zope.publisher.interfaces.browser import IBrowserRequest +from zope.app.renderer.interfaces import ISource, IHTMLRenderer +from zope.app.renderer import SourceFactory from zope.schema import vocabulary from zope import thread +import markdown import cybertools from loops.browser.util import html_quote @@ -35,6 +40,7 @@ _ = MessageFactory('loops') renderingFactories = { + 'text/markdown': 'loops.util.markdown', 'text/plain': 'zope.source.plaintext', 'text/stx': 'zope.source.stx', 'text/structured': 'zope.source.stx', @@ -42,6 +48,24 @@ renderingFactories = { 'text/restructured': 'zope.source.rest', } +class IMarkdownSource(ISource): + """Marker interface for a restructured text source. Note that an + implementation of this interface should always derive from unicode or + behave like a unicode class.""" + + +MarkdownSourceFactory = SourceFactory( + IMarkdownSource, _("Markdown(md))"), + _("Markdown(md) Source")) + +class MarkdownToHTMLRenderer(BrowserView): + + implements(IHTMLRenderer) + component.adapts(IMarkdownSource, IBrowserRequest) + + def render(self, settings_overrides={}): + return markdown.markdown(self.context) + class KeywordVocabulary(vocabulary.SimpleVocabulary):