##// END OF EJS Templates
catch errors on renderers, and display plain if critical rendering error is present
marcink -
r2747:cdce3d72 beta
parent child Browse files
Show More
@@ -26,6 +26,7 b''
26
26
27 import re
27 import re
28 import logging
28 import logging
29 import traceback
29
30
30 from rhodecode.lib.utils2 import safe_unicode, MENTIONS_REGEX
31 from rhodecode.lib.utils2 import safe_unicode, MENTIONS_REGEX
31
32
@@ -93,7 +94,7 b' class MarkupRenderer(object):'
93 return '<br />' + source.replace("\n", '<br />')
94 return '<br />' + source.replace("\n", '<br />')
94
95
95 @classmethod
96 @classmethod
96 def markdown(cls, source):
97 def markdown(cls, source, safe=True):
97 source = safe_unicode(source)
98 source = safe_unicode(source)
98 try:
99 try:
99 import markdown as __markdown
100 import markdown as __markdown
@@ -101,9 +102,15 b' class MarkupRenderer(object):'
101 except ImportError:
102 except ImportError:
102 log.warning('Install markdown to use this function')
103 log.warning('Install markdown to use this function')
103 return cls.plain(source)
104 return cls.plain(source)
105 except Exception:
106 log.error(traceback.format_exc())
107 if safe:
108 return source
109 else:
110 raise
104
111
105 @classmethod
112 @classmethod
106 def rst(cls, source):
113 def rst(cls, source, safe=True):
107 source = safe_unicode(source)
114 source = safe_unicode(source)
108 try:
115 try:
109 from docutils.core import publish_parts
116 from docutils.core import publish_parts
@@ -125,6 +132,12 b' class MarkupRenderer(object):'
125 except ImportError:
132 except ImportError:
126 log.warning('Install docutils to use this function')
133 log.warning('Install docutils to use this function')
127 return cls.plain(source)
134 return cls.plain(source)
135 except Exception:
136 log.error(traceback.format_exc())
137 if safe:
138 return source
139 else:
140 raise
128
141
129 @classmethod
142 @classmethod
130 def rst_with_mentions(cls, source):
143 def rst_with_mentions(cls, source):
General Comments 0
You need to be logged in to leave comments. Login now