Template filter implementing the Trac wiki markup language

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"""
Usage:

{% load tracwiki %}

{{ object.body|tracwiki }}

# Logic from http://groups.google.com/group/trac-dev/msg/479decac43883dc0
"""

from trac.test import EnvironmentStub, Mock, MockPerm 
from trac.mimeview import Context 
from trac.wiki.formatter import HtmlFormatter 
from trac.web.href import Href

from django.utils.safestring import mark_safe
from django import template
register = template.Library()

env = EnvironmentStub() 
req = Mock(href=Href('/'), abs_href=Href('http://www.example.com/'), 
           authname='anonymous', perm=MockPerm(), args={})
context = Context.from_request(req, 'wiki')

@register.filter
def tracwiki(s):
    return mark_safe(HtmlFormatter(env, context, s).generate())

More like this

  1. extending generic_markup.apply_markup by mandric 6 years, 11 months ago
  2. TRAC-Ticket on exception by identify 4 years, 9 months ago
  3. Template Filter: Add indentation by Chuck Harmston 4 years, 7 months ago
  4. MediaWiki Markup by zeeg 7 years ago
  5. render_markup filter, specify the markup filter as a string by exogen 7 years ago

Comments

tutuca (on April 23, 2009):

It fails to use the [Image()] macro. But for works flawlessy rendering text

#

albertorcf (on October 21, 2010):

failed to render a wiki link like

[wiki:DoSomeThing do some thing]

change the next line to correct this

context = Context.from_request(req, id='wiki')

#

albertorcf (on October 21, 2010):

or simply remove the parameter:

context = Context.from_request(req)

tested at Trac version 0.12.1

I will see more about the resource parameter to find how improve these wiki links

#

(Forgotten your password?)