I am trying to render trac wiki markdown format as html for display on my website. I tried following this other SO question 'how do i use trac wiki formatting', but the code snippet returns an error when I run it. It should be noted that the question and code are nearly 4 years old. Any idea how I can get this to work?
In my urls.py i simply call the tracwiki
(from the snippet) view.
# urls.py
url(r'^$', 'tracwiki', name='index'),
# views.py
"""
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())
Here is the error returned:
[01/Apr/2014 18:40:53] "GET / HTTP/1.1" 500 60948
AttributeError at /
'SafeText' object has no attribute 'get'
Request Method: GET
Request URL: http://xxx.xxx.xxx.xxx/
Django Version: 1.5.5
Exception Type: AttributeError
Exception Value:
'SafeText' object has no attribute 'get'
Exception Location: /mysite/local/lib/python2.7/site-packages/django/middleware/clickjacking.py in process_response, line 30
Python Executable: /Envs/mysite/bin/python
Python Version: 2.7.5