Commits

James Rivett-Carnac committed 656e1ee

wrong names and saving

  • Participants
  • Parent commits 0b4fa8a
  • Branches lexical_hilight

Comments (0)

Files changed (2)

File diario/utils/colourize.py

-from diario.settings import DIARIO_USE_COLOURS
-from diario.settings import DIARIO_COLOUR_CLASS
-
-if DIARIO_USE_COLOURS:
-    from pygments.lexers import LEXERS, get_lexer_by_name, guess_lexer
-    from pygments import highlight
-    from pygments.formatters import HtmlFormatter
-    from BeautifulSoup import BeautifulSoup
-
-    _lexer_names = reduce(lambda a,b: a + b[2], LEXERS.itervalues(), ())
-    _formatter = HtmlFormatter(cssclass='source')
-
-    TAGS = ('pre',)
-
-    def colourize(html):
-        """
-        Colourize code blocks in a marked-up stream, using pygments
-
-        This lets you set a few things, such as code and css, what tags, etc,
-        and is markup agnostic (ish), there are other options like using 
-        markdown's codehilite module.
-        """
-        soup = BeautifulSoup(html)
-        for node in soup.findAll(TAGS):
-            lexer_name = node.get('class')
-            # There is now a question on if there is a 'code' block inside
-            # the pre block
-            bottom_node = node.code
-            if not code_node:
-                bottom_node = node
-            if not lexer_name or (lexer_name not in  _lexer_names):
-                lexer = guess_lexer(node.renderContents())
-            elif lexer_name in _lexer_names:
-                lexer = get_lexer_by_name(lexer_name, stripnl=True, encoding='UTF-8')
-            spam = BeautifulSoup(highlight(bottom_node.renderContents(), lexer, _formatter))
-            bottom_node.replaceWith(spam) # Spam Soup!
-        return unicode(soup)
-
-def markuping(markup, value):
-    """
-    Transform plain text markup syntaxes to HTML with filters in
-    django.contrib.markup.templatetags.
-
-    Does lexical higlighting if DIARIO_USE_COLOURS is true.  This is not 
-    guarunteed to be identical between the colourize(html) method and the
-    Markdown codehilite method.
-
-    *Required arguments:*
-
-        * ``markup``: 'markdown', 'rest' or 'texttile'. For any other string
-                    value is returned without modifications.
-        * ``value``: plain text input
-
-    """
-    output = value
-    if markup == 'markdown':
-        from markdown import markdown
-        if DIARIO_USE_COLOURS:
-            return markdown.markdown(value,
-                    ['codehilite(css_class={0})'.format(DIARIO_COLOUR_CLASS)]
-                    )
-        output = markdown(value)
-    elif markup == 'rest':
-        from django.contrib.markup.templatetags.markup import restructuredtext
-        output = restructuredtext(value)
-    elif markup == 'textile':
-        from django.contrib.markup.templatetags.markup import textile
-        output = textile(value)
-    else:
-        return value            # raw
-    if DIARIO_USE_COLOURS:
-        # Markdown uses the the codehilite extension and should
-        # return before getting here.
-        return colourize(output)
-    else:
-        return output

File diario/utils/markup.py

+from diario.settings import DIARIO_USE_COLOURS
+from diario.settings import DIARIO_COLOUR_CLASS
+
+if DIARIO_USE_COLOURS:
+    from pygments.lexers import LEXERS, get_lexer_by_name, guess_lexer
+    from pygments import highlight
+    from pygments.formatters import HtmlFormatter
+    from BeautifulSoup import BeautifulSoup
+
+    _lexer_names = reduce(lambda a,b: a + b[2], LEXERS.itervalues(), ())
+    _formatter = HtmlFormatter(cssclass='source')
+
+    TAGS = ('pre',)
+
+    def colourize(html):
+        """
+        Colourize code blocks in a marked-up stream, using pygments
+
+        This lets you set a few things, such as code and css, what tags, etc,
+        and is markup agnostic (ish), there are other options like using 
+        markdown's codehilite module.
+        """
+        soup = BeautifulSoup(html)
+        for node in soup.findAll(TAGS):
+            lexer_name = node.get('class')
+            # There is now a question on if there is a 'code' block inside
+            # the pre block
+            bottom_node = node.code
+            if not code_node:
+                bottom_node = node
+            if not lexer_name or (lexer_name not in  _lexer_names):
+                lexer = guess_lexer(node.renderContents())
+            elif lexer_name in _lexer_names:
+                lexer = get_lexer_by_name(lexer_name, stripnl=True, encoding='UTF-8')
+            spam = BeautifulSoup(highlight(bottom_node.renderContents(), lexer, _formatter))
+            bottom_node.replaceWith(spam) # Spam Soup!
+        return unicode(soup)
+
+def markuping(markup, value):
+    """
+    Transform plain text markup syntaxes to HTML with filters in
+    django.contrib.markup.templatetags.
+
+    Does lexical higlighting if DIARIO_USE_COLOURS is true.  This is not 
+    guarunteed to be identical between the colourize(html) method and the
+    Markdown codehilite method.
+
+    *Required arguments:*
+
+        * ``markup``: 'markdown', 'rest' or 'texttile'. For any other string
+                    value is returned without modifications.
+        * ``value``: plain text input
+
+    """
+    output = value
+    if markup == 'markdown':
+        from markdown import markdown
+        if DIARIO_USE_COLOURS:
+            return markdown.markdown(value,
+                    ['codehilite(css_class={0})'.format(DIARIO_COLOUR_CLASS)]
+                    )
+        output = markdown(value)
+    elif markup == 'rest':
+        from django.contrib.markup.templatetags.markup import restructuredtext
+        output = restructuredtext(value)
+    elif markup == 'textile':
+        from django.contrib.markup.templatetags.markup import textile
+        output = textile(value)
+    else:
+        return value            # raw
+    if DIARIO_USE_COLOURS:
+        # Markdown uses the the codehilite extension and should
+        # return before getting here.
+        return colourize(output)
+    else:
+        return output