Changeset - cdce3d7282b2
[Not reviewed]
beta
0 1 0
Marcin Kuzminski - 13 years ago 2012-08-27 10:15:36
marcin@python-works.com
catch errors on renderers, and display plain if critical rendering error is present
1 file changed with 15 insertions and 2 deletions:
0 comments (0 inline, 0 general)
rhodecode/lib/markup_renderer.py
Show inline comments
 
@@ -23,12 +23,13 @@
 
#
 
# You should have received a copy of the GNU General Public License
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 

	
 
import re
 
import logging
 
import traceback
 

	
 
from rhodecode.lib.utils2 import safe_unicode, MENTIONS_REGEX
 

	
 
log = logging.getLogger(__name__)
 

	
 

	
 
@@ -90,23 +91,29 @@ class MarkupRenderer(object):
 
            return url_pat.sub(url_func, text)
 

	
 
        source = urlify_text(source)
 
        return '<br />' + source.replace("\n", '<br />')
 

	
 
    @classmethod
 
    def markdown(cls, source):
 
    def markdown(cls, source, safe=True):
 
        source = safe_unicode(source)
 
        try:
 
            import markdown as __markdown
 
            return __markdown.markdown(source, ['codehilite'])
 
        except ImportError:
 
            log.warning('Install markdown to use this function')
 
            return cls.plain(source)
 
        except Exception:
 
            log.error(traceback.format_exc())
 
            if safe:
 
                return source
 
            else:
 
                raise
 

	
 
    @classmethod
 
    def rst(cls, source):
 
    def rst(cls, source, safe=True):
 
        source = safe_unicode(source)
 
        try:
 
            from docutils.core import publish_parts
 
            from docutils.parsers.rst import directives
 
            docutils_settings = dict([(alias, None) for alias in
 
                                cls.RESTRUCTUREDTEXT_DISALLOWED_DIRECTIVES])
 
@@ -122,12 +129,18 @@ class MarkupRenderer(object):
 
                                  settings_overrides=docutils_settings)
 

	
 
            return parts['html_title'] + parts["fragment"]
 
        except ImportError:
 
            log.warning('Install docutils to use this function')
 
            return cls.plain(source)
 
        except Exception:
 
            log.error(traceback.format_exc())
 
            if safe:
 
                return source
 
            else:
 
                raise
 

	
 
    @classmethod
 
    def rst_with_mentions(cls, source):
 
        mention_pat = re.compile(MENTIONS_REGEX)
 

	
 
        def wrapp(match_obj):
0 comments (0 inline, 0 general)