changeset 1996:0592987973eb beta

activate codehilite extension on markdown renderer, inspired by bitbucket blog ;)
author Marcin Kuzminski <marcin@python-works.com>
date Fri, 17 Feb 2012 01:03:02 +0200
parents b6c902d88472
children a318f5baf53a
files rhodecode/lib/markup_renderer.py rhodecode/public/css/pygments.css
diffstat 2 files changed, 69 insertions(+), 70 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/lib/markup_renderer.py	Thu Feb 16 05:41:58 2012 +0200
+++ b/rhodecode/lib/markup_renderer.py	Fri Feb 17 01:03:02 2012 +0200
@@ -31,12 +31,13 @@
 
 log = logging.getLogger(__name__)
 
+
 class MarkupRenderer(object):
     RESTRUCTUREDTEXT_DISALLOWED_DIRECTIVES = ['include', 'meta', 'raw']
 
-    MARKDOWN_PAT = re.compile(r'md|mkdn?|mdown|markdown',re.IGNORECASE)
-    RST_PAT = re.compile(r're?st',re.IGNORECASE)
-    PLAIN_PAT = re.compile(r'readme',re.IGNORECASE)
+    MARKDOWN_PAT = re.compile(r'md|mkdn?|mdown|markdown', re.IGNORECASE)
+    RST_PAT = re.compile(r're?st', re.IGNORECASE)
+    PLAIN_PAT = re.compile(r'readme', re.IGNORECASE)
 
     def __detect_renderer(self, source, filename=None):
         """
@@ -60,7 +61,6 @@
 
         return getattr(MarkupRenderer, detected_renderer)
 
-
     def render(self, source, filename=None):
         """
         Renders a given filename using detected renderer
@@ -78,31 +78,30 @@
     @classmethod
     def plain(cls, source):
         source = safe_unicode(source)
+
         def urlify_text(text):
             url_pat = re.compile(r'(http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]'
                                  '|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+)')
 
             def url_func(match_obj):
                 url_full = match_obj.groups()[0]
-                return '<a href="%(url)s">%(url)s</a>' % ({'url':url_full})
+                return '<a href="%(url)s">%(url)s</a>' % ({'url': url_full})
 
             return url_pat.sub(url_func, text)
 
         source = urlify_text(source)
         return '<br />' + source.replace("\n", '<br />')
 
-
     @classmethod
     def markdown(cls, source):
         source = safe_unicode(source)
         try:
             import markdown as __markdown
-            return __markdown.markdown(source)
+            return __markdown.markdown(source, ['codehilite'])
         except ImportError:
             log.warning('Install markdown to use this function')
             return cls.plain(source)
 
-
     @classmethod
     def rst(cls, source):
         source = safe_unicode(source)
@@ -113,7 +112,7 @@
                                 cls.RESTRUCTUREDTEXT_DISALLOWED_DIRECTIVES])
 
             docutils_settings.update({'input_encoding': 'unicode',
-                                      'report_level':4})
+                                      'report_level': 4})
 
             for k, v in docutils_settings.iteritems():
                 directives.register_directive(k, v)
--- a/rhodecode/public/css/pygments.css	Thu Feb 16 05:41:58 2012 +0200
+++ b/rhodecode/public/css/pygments.css	Fri Feb 17 01:03:02 2012 +0200
@@ -106,64 +106,64 @@
 .linenos a { text-decoration: none; }
 
 .code { display: block; }
-.code-highlight .hll { background-color: #ffffcc }
-.code-highlight .c { color: #408080; font-style: italic } /* Comment */
-.code-highlight .err { border: 1px solid #FF0000 } /* Error */
-.code-highlight .k { color: #008000; font-weight: bold } /* Keyword */
-.code-highlight .o { color: #666666 } /* Operator */
-.code-highlight .cm { color: #408080; font-style: italic } /* Comment.Multiline */
-.code-highlight .cp { color: #BC7A00 } /* Comment.Preproc */
-.code-highlight .c1 { color: #408080; font-style: italic } /* Comment.Single */
-.code-highlight .cs { color: #408080; font-style: italic } /* Comment.Special */
-.code-highlight .gd { color: #A00000 } /* Generic.Deleted */
-.code-highlight .ge { font-style: italic } /* Generic.Emph */
-.code-highlight .gr { color: #FF0000 } /* Generic.Error */
-.code-highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */
-.code-highlight .gi { color: #00A000 } /* Generic.Inserted */
-.code-highlight .go { color: #808080 } /* Generic.Output */
-.code-highlight .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
-.code-highlight .gs { font-weight: bold } /* Generic.Strong */
-.code-highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
-.code-highlight .gt { color: #0040D0 } /* Generic.Traceback */
-.code-highlight .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
-.code-highlight .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
-.code-highlight .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
-.code-highlight .kp { color: #008000 } /* Keyword.Pseudo */
-.code-highlight .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
-.code-highlight .kt { color: #B00040 } /* Keyword.Type */
-.code-highlight .m { color: #666666 } /* Literal.Number */
-.code-highlight .s { color: #BA2121 } /* Literal.String */
-.code-highlight .na { color: #7D9029 } /* Name.Attribute */
-.code-highlight .nb { color: #008000 } /* Name.Builtin */
-.code-highlight .nc { color: #0000FF; font-weight: bold } /* Name.Class */
-.code-highlight .no { color: #880000 } /* Name.Constant */
-.code-highlight .nd { color: #AA22FF } /* Name.Decorator */
-.code-highlight .ni { color: #999999; font-weight: bold } /* Name.Entity */
-.code-highlight .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
-.code-highlight .nf { color: #0000FF } /* Name.Function */
-.code-highlight .nl { color: #A0A000 } /* Name.Label */
-.code-highlight .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
-.code-highlight .nt { color: #008000; font-weight: bold } /* Name.Tag */
-.code-highlight .nv { color: #19177C } /* Name.Variable */
-.code-highlight .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
-.code-highlight .w { color: #bbbbbb } /* Text.Whitespace */
-.code-highlight .mf { color: #666666 } /* Literal.Number.Float */
-.code-highlight .mh { color: #666666 } /* Literal.Number.Hex */
-.code-highlight .mi { color: #666666 } /* Literal.Number.Integer */
-.code-highlight .mo { color: #666666 } /* Literal.Number.Oct */
-.code-highlight .sb { color: #BA2121 } /* Literal.String.Backtick */
-.code-highlight .sc { color: #BA2121 } /* Literal.String.Char */
-.code-highlight .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */
-.code-highlight .s2 { color: #BA2121 } /* Literal.String.Double */
-.code-highlight .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
-.code-highlight .sh { color: #BA2121 } /* Literal.String.Heredoc */
-.code-highlight .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
-.code-highlight .sx { color: #008000 } /* Literal.String.Other */
-.code-highlight .sr { color: #BB6688 } /* Literal.String.Regex */
-.code-highlight .s1 { color: #BA2121 } /* Literal.String.Single */
-.code-highlight .ss { color: #19177C } /* Literal.String.Symbol */
-.code-highlight .bp { color: #008000 } /* Name.Builtin.Pseudo */
-.code-highlight .vc { color: #19177C } /* Name.Variable.Class */
-.code-highlight .vg { color: #19177C } /* Name.Variable.Global */
-.code-highlight .vi { color: #19177C } /* Name.Variable.Instance */
-.code-highlight .il { color: #666666 } /* Literal.Number.Integer.Long */
+.code-highlight .hll, .codehilite .hll { background-color: #ffffcc }
+.code-highlight .c, .codehilite .c { color: #408080; font-style: italic } /* Comment */
+.code-highlight .err, .codehilite .err { border: 1px solid #FF0000 } /* Error */
+.code-highlight .k, .codehilite .k { color: #008000; font-weight: bold } /* Keyword */
+.code-highlight .o, .codehilite .o { color: #666666 } /* Operator */
+.code-highlight .cm, .codehilite .cm { color: #408080; font-style: italic } /* Comment.Multiline */
+.code-highlight .cp, .codehilite .cp { color: #BC7A00 } /* Comment.Preproc */
+.code-highlight .c1, .codehilite .c1 { color: #408080; font-style: italic } /* Comment.Single */
+.code-highlight .cs, .codehilite .cs { color: #408080; font-style: italic } /* Comment.Special */
+.code-highlight .gd, .codehilite .gd { color: #A00000 } /* Generic.Deleted */
+.code-highlight .ge, .codehilite .ge { font-style: italic } /* Generic.Emph */
+.code-highlight .gr, .codehilite .gr { color: #FF0000 } /* Generic.Error */
+.code-highlight .gh, .codehilite .gh { color: #000080; font-weight: bold } /* Generic.Heading */
+.code-highlight .gi, .codehilite .gi { color: #00A000 } /* Generic.Inserted */
+.code-highlight .go, .codehilite .go { color: #808080 } /* Generic.Output */
+.code-highlight .gp, .codehilite .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
+.code-highlight .gs, .codehilite .gs { font-weight: bold } /* Generic.Strong */
+.code-highlight .gu, .codehilite .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
+.code-highlight .gt, .codehilite .gt { color: #0040D0 } /* Generic.Traceback */
+.code-highlight .kc, .codehilite .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
+.code-highlight .kd, .codehilite .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
+.code-highlight .kn, .codehilite .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
+.code-highlight .kp, .codehilite .kp { color: #008000 } /* Keyword.Pseudo */
+.code-highlight .kr, .codehilite .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
+.code-highlight .kt, .codehilite .kt { color: #B00040 } /* Keyword.Type */
+.code-highlight .m, .codehilite .m { color: #666666 } /* Literal.Number */
+.code-highlight .s, .codehilite .s { color: #BA2121 } /* Literal.String */
+.code-highlight .na, .codehilite .na { color: #7D9029 } /* Name.Attribute */
+.code-highlight .nb, .codehilite .nb { color: #008000 } /* Name.Builtin */
+.code-highlight .nc, .codehilite .nc { color: #0000FF; font-weight: bold } /* Name.Class */
+.code-highlight .no, .codehilite .no { color: #880000 } /* Name.Constant */
+.code-highlight .nd, .codehilite .nd { color: #AA22FF } /* Name.Decorator */
+.code-highlight .ni, .codehilite .ni { color: #999999; font-weight: bold } /* Name.Entity */
+.code-highlight .ne, .codehilite .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
+.code-highlight .nf, .codehilite .nf { color: #0000FF } /* Name.Function */
+.code-highlight .nl, .codehilite .nl { color: #A0A000 } /* Name.Label */
+.code-highlight .nn, .codehilite .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
+.code-highlight .nt, .codehilite .nt { color: #008000; font-weight: bold } /* Name.Tag */
+.code-highlight .nv, .codehilite .nv { color: #19177C } /* Name.Variable */
+.code-highlight .ow, .codehilite .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
+.code-highlight .w, .codehilite .w { color: #bbbbbb } /* Text.Whitespace */
+.code-highlight .mf, .codehilite .mf { color: #666666 } /* Literal.Number.Float */
+.code-highlight .mh, .codehilite .mh { color: #666666 } /* Literal.Number.Hex */
+.code-highlight .mi, .codehilite .mi { color: #666666 } /* Literal.Number.Integer */
+.code-highlight .mo, .codehilite .mo { color: #666666 } /* Literal.Number.Oct */
+.code-highlight .sb, .codehilite .sb { color: #BA2121 } /* Literal.String.Backtick */
+.code-highlight .sc, .codehilite .sc { color: #BA2121 } /* Literal.String.Char */
+.code-highlight .sd, .codehilite .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */
+.code-highlight .s2, .codehilite .s2 { color: #BA2121 } /* Literal.String.Double */
+.code-highlight .se, .codehilite .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
+.code-highlight .sh, .codehilite .sh { color: #BA2121 } /* Literal.String.Heredoc */
+.code-highlight .si, .codehilite .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
+.code-highlight .sx, .codehilite .sx { color: #008000 } /* Literal.String.Other */
+.code-highlight .sr, .codehilite .sr { color: #BB6688 } /* Literal.String.Regex */
+.code-highlight .s1, .codehilite .s1 { color: #BA2121 } /* Literal.String.Single */
+.code-highlight .ss, .codehilite .ss { color: #19177C } /* Literal.String.Symbol */
+.code-highlight .bp, .codehilite .bp { color: #008000 } /* Name.Builtin.Pseudo */
+.code-highlight .vc, .codehilite .vc { color: #19177C } /* Name.Variable.Class */
+.code-highlight .vg, .codehilite .vg { color: #19177C } /* Name.Variable.Global */
+.code-highlight .vi, .codehilite .vi { color: #19177C } /* Name.Variable.Instance */
+.code-highlight .il, .codehilite .il { color: #666666 } /* Literal.Number.Integer.Long */