add markdown support
This commit is contained in:
parent
d863305b94
commit
7f7a2af25f
3 changed files with 40 additions and 4 deletions
|
@ -1,6 +1,7 @@
|
||||||
<configure
|
<configure
|
||||||
xmlns="http://namespaces.zope.org/zope"
|
xmlns="http://namespaces.zope.org/zope"
|
||||||
xmlns:i18n="http://namespaces.zope.org/i18n"
|
xmlns:i18n="http://namespaces.zope.org/i18n"
|
||||||
|
xmlns:browser="http://namespaces.zope.org/browser"
|
||||||
i18n_domain="loops">
|
i18n_domain="loops">
|
||||||
|
|
||||||
<i18n:registerTranslations directory="locales" />
|
<i18n:registerTranslations directory="locales" />
|
||||||
|
@ -478,6 +479,19 @@
|
||||||
component="loops.view.NodeTypeSourceList"
|
component="loops.view.NodeTypeSourceList"
|
||||||
name="loops.nodeTypeSource" />
|
name="loops.nodeTypeSource" />
|
||||||
|
|
||||||
|
<!-- Markdown support -->
|
||||||
|
|
||||||
|
<utility
|
||||||
|
component="loops.util.MarkdownSourceFactory"
|
||||||
|
name="loops.util.markdown"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<browser:view
|
||||||
|
name=""
|
||||||
|
for="loops.util.IMarkdownSource"
|
||||||
|
class="loops.util.MarkdownToHTMLRenderer"
|
||||||
|
permission="zope.Public" />
|
||||||
|
|
||||||
|
|
||||||
<include package=".browser" />
|
<include package=".browser" />
|
||||||
<include package=".classifier" />
|
<include package=".classifier" />
|
||||||
|
|
|
@ -402,7 +402,7 @@ class IDocumentSchema(IResourceSchema):
|
||||||
contentType = schema.Choice(
|
contentType = schema.Choice(
|
||||||
title=_(u'Content Type'),
|
title=_(u'Content Type'),
|
||||||
description=_(u'Content type (format) of the data field'),
|
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'),
|
'text/plain', 'text/xml', 'text/css'),
|
||||||
default='text/restructured',
|
default='text/restructured',
|
||||||
required=True)
|
required=True)
|
||||||
|
@ -968,5 +968,3 @@ class IViewConfiguratorSchema(Interface):
|
||||||
value_type=schema.TextLine(),
|
value_type=schema.TextLine(),
|
||||||
default=[],
|
default=[],
|
||||||
required=False)
|
required=False)
|
||||||
|
|
||||||
|
|
||||||
|
|
26
util.py
26
util.py
|
@ -21,12 +21,17 @@ Utility functions.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
from zope.publisher.browser import BrowserView
|
||||||
from zope import component
|
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.intid.interfaces import IIntIds
|
||||||
from zope.i18nmessageid import MessageFactory
|
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.schema import vocabulary
|
||||||
from zope import thread
|
from zope import thread
|
||||||
|
import markdown
|
||||||
|
|
||||||
import cybertools
|
import cybertools
|
||||||
from loops.browser.util import html_quote
|
from loops.browser.util import html_quote
|
||||||
|
@ -35,6 +40,7 @@ _ = MessageFactory('loops')
|
||||||
|
|
||||||
|
|
||||||
renderingFactories = {
|
renderingFactories = {
|
||||||
|
'text/markdown': 'loops.util.markdown',
|
||||||
'text/plain': 'zope.source.plaintext',
|
'text/plain': 'zope.source.plaintext',
|
||||||
'text/stx': 'zope.source.stx',
|
'text/stx': 'zope.source.stx',
|
||||||
'text/structured': 'zope.source.stx',
|
'text/structured': 'zope.source.stx',
|
||||||
|
@ -42,6 +48,24 @@ renderingFactories = {
|
||||||
'text/restructured': 'zope.source.rest',
|
'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):
|
class KeywordVocabulary(vocabulary.SimpleVocabulary):
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue