django-markitup / markitup / markup.py

"""
markup filters for django-markitup

Time-stamp: <2009-03-18 11:44:57 carljm markup.py>

This module provides a ``filter_func`` module-level markup filter
function based on the MARKITUP_PREVIEW_FILTER setting.

MARKITUP_PREVIEW_FILTER should be a two-tuple, where the first element
is a dotted-path string to a markup filter function, and the second
element is a dictionary of kwargs to be passed to the filter function
along with the markup to parse.

For instance, if MARKITUP_PREVIEW_FILTER is set to::

    ('markdown.markdown', {'safe_mode': True})

then calling ``filter_func(text)`` is equivalent to::

    from markdown import markdown
    markdown(text, safe_mode=True)

Though the implementation differs, the format of the
MARKITUP_PREVIEW_FILTER setting is inspired by James Bennett's
django-template-utils_.

.. _django-template-utils: http://code.google.com/p/django-template-utils/

"""
from django.utils.functional import curry, wraps

from markitup.settings import MARKITUP_PREVIEW_FILTER

if MARKITUP_PREVIEW_FILTER is None:
    filter_func = lambda text: text
else:
    filter_path, filter_kwargs = MARKITUP_PREVIEW_FILTER
    module, funcname = filter_path.rsplit('.', 1)
    func = getattr(__import__(module, {}, {}, [funcname]), funcname)
    filter_func = wraps(func)(curry(func, **filter_kwargs))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.