view core/markup.py @ 693:ad69236e8501

For issue #52, update many 3rd party Javascript libraries. Updated to jquery 1.10.2, jquery ui 1.10.3. This broke a lot of stuff. - Found a newer version of the jquery cycle all plugin (3.0.3). - Updated JPlayer to 2.4.0. - Updated to MarkItUp 1.1.14. This also required me to add multiline attributes set to true on various buttons in the markdown set. - As per a stackoverflow post, added some code to get multiline titles in a jQuery UI dialog. They removed that functionality but allow you to put it back. Tweaked the MarkItUp preview CSS to show blockquotes in italic. Did not update TinyMCE at this time. I'm not using the JQuery version and this version appears to work ok for now. What I should do is make a repo for MarkItUp and do a vendor branch thing so I don't have to futz around diffing directories to figure out if I'll lose changes when I update.
author Brian Neal <bgneal@gmail.com>
date Wed, 04 Sep 2013 19:55:20 -0500
parents 216f06267e2d
children 7429c98c8ece
line wrap: on
line source
"""
Markup related utitlities useful for the entire project.
"""
import markdown as _markdown
from django.utils.encoding import force_unicode

from smiley import SmilifyMarkdown

class Markdown(object):
    """
    This is a thin wrapper around the Markdown class which deals with the
    differences in Markdown versions on the production and development server.
    This code was inspired by the code in
    django/contrib/markup/templatetags/markup.py.
    Currently, we only have to worry about Markdown 1.6b and 2.0.
    """
    def __init__(self, safe_mode='escape'):
        self.md = _markdown.Markdown(safe_mode=safe_mode,
                                extensions=['urlize', 'nl2br', 'del'])

    def convert(self, s):
        return self.md.convert(force_unicode(s))


def markdown(s):
    """
    A convenience function for one-off markdown jobs.
    """
    md = Markdown()
    return md.convert(s)


class SiteMarkup(object):
    """
    This class provides site markup by combining markdown and
    our own smiley markup.
    """
    def __init__(self):
        self.md = Markdown()
        self.smiley = SmilifyMarkdown()

    def convert(self, s):
        return self.md.convert(self.smiley.convert(s))


def site_markup(s):
    """
    Convenience function for one-off site markup jobs.
    """
    sm = SiteMarkup()
    return sm.convert(s)