Carl Meyer  committed ce853ec

add render_markup template filter

  • Participants
  • Parent commits c3958af

Comments (0)

Files changed (4)

 tip (unreleased)
+- add render_markup template filter
 - update to jQuery 1.4 and MarkItUp! 1.1.6
 - Add auto_preview option.
 - Ajax preview view now uses RequestContext, and additionally passes
   ``MARKITUP_MEDIA_URL`` into the template context. (Previously,
-  ``MARKITUP_MEDIA_URL`` was passed as ``MEDIA_URL`` and RequestContext was
-  not used).
+  ``MARKITUP_MEDIA_URL`` was passed as ``MEDIA_URL`` and
+  RequestContext was not used). Backwards-incompatible; may require
+  change to preview template.
 0.5.2 (2009.11.24)
 ``django-markitup`` provides one sample rendering function,
 ``render_rest`` in the ``markitup.renderers`` module.
+render_markup template filter
+If you have set `the MARKITUP_FILTER setting`_ and use the MarkItUp!
+AJAX preview, but don't wish to store rendered markup in the database
+with `MarkupField`_ (or are using third-party models that don't use
+`MarkupField`_), you may want a convenient way to render content in
+your templates using your MARKITUP_FILTER function. For this you can
+use the ``render_markup`` template filter::
+    {% load markitup_tags %}
+    {{ post.content|render_markup }}
 Other settings

File markitup/templatetags/

 from django.conf import settings as django_settings
 from markitup import settings
 from markitup.util import absolute_url
+from markitup.fields import render_func
 register = template.Library()
+def render_markup(content):
+    return render_func(content)
 # we do some funny stuff here for testability (the tests need to be
 # able to force a recalculation of this context)
 def _get_markitup_context():

File tests/

             self.assertIn('jquery.markitup.js', out)
+class TemplatefilterTests(MIUTestCase):
+    def test_render_markup(self):
+        tpl_string = "{% load markitup_tags %}{{ content|render_markup }}"
+        self.assertEquals('replacement text', self.render(tpl_string,
+                                                          {'content': 'replace this text'}))
 class RenderTests(MIUTestCase):
     look_for = '$("#my_id").markItUp(mySettings);'
     auto_preview_override = True