Browse files

Django template tag to render Trac syntax.

  • Loading branch information...
1 parent a24000b commit db98dc0817b7266e19e9fff4f0f0f451f7b14f06 @mitar committed Jun 13, 2012
Showing with 14 additions and 3 deletions.
  1. +7 −2 cmsplugin_markup_tracwiki/templatetags/tracwiki.py
  2. +7 −1 docs/index.rst
View
9 cmsplugin_markup_tracwiki/templatetags/tracwiki.py
@@ -20,13 +20,18 @@ def extract_link(self, value, context):
ctx, req = self._prepare_environment(context)
return self._formatter(self.env, ctx).match(u'[%s]' % value)
-parser = ExtractLink()
+link_parser = ExtractLink()
+parser = tracwiki.Markup()
@register.simple_tag(takes_context=True)
def tracwiki_link(context, value):
- elt = parser.extract_link(value.strip(), context)
+ elt = link_parser.extract_link(value.strip(), context)
elt = html.find_element(elt, 'href')
if elt is not None:
return elt.attrib.get('href')
else:
return value
+
+@register.simple_tag(takes_context=True)
+def tracwiki(context, value):
+ return parser.parse(value, context)
View
8 docs/index.rst
@@ -67,12 +67,18 @@ clone the repository and implement them yourself and send me a pull request.
Template Tags
-------------
+If you want to render Trac syntax in Django templates, you can use ``tracwiki``
+Django template tag from ``tracwiki`` template tags library::
+
+ {% load tracwiki %}
+ {% tracwiki object.trac_content %}
+
If you want to process Trac links (Trac link syntax) in Django templates, you
can use ``tracwiki_link`` Django template tag from ``tracwiki`` template tags
library::
{% load tracwiki %}
- <a href="{% tracwiki_link "cms:admin:index" %}">Admin main page</a>
+ <a href="{% tracwiki_link "filer:original-filename.png" %}">File</a>
Settings
--------

0 comments on commit db98dc0

Please sign in to comment.