use markdown import and content type only when available

This commit is contained in:
Helmut Merz 2017-12-29 10:37:13 +01:00
parent 8c09a0e73d
commit a13784e93e

11
util.py
View file

@ -1,5 +1,5 @@
# #
# Copyright (c) 2012 Helmut Merz helmutm@cy55.de # Copyright (c) 2017 Helmut Merz helmutm@cy55.de
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -31,7 +31,10 @@ from zope.app.renderer.interfaces import ISource, IHTMLRenderer
from zope.app.renderer import SourceFactory 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 try:
import markdown
except ImportError:
markdown = None
import cybertools import cybertools
from loops.browser.util import html_quote from loops.browser.util import html_quote
@ -40,7 +43,6 @@ _ = 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',
@ -48,6 +50,9 @@ renderingFactories = {
'text/restructured': 'zope.source.rest', 'text/restructured': 'zope.source.rest',
} }
if markdown:
renderingFactories['text/markdown'] = 'loops.util.markdown'
class IMarkdownSource(ISource): class IMarkdownSource(ISource):
"""Marker interface for a restructured text source. Note that an """Marker interface for a restructured text source. Note that an
implementation of this interface should always derive from unicode or implementation of this interface should always derive from unicode or