I have written for a personal django app (actually a blog), a new
restructured text role that allows to use TeX syntax and rendering math
formulas; the problem is that I don't want to allow this in comment. To
avoid to load the TeX related role I use the following snippet of code
where I delete the role directly by popping it from roles._role_registry
dictionary
@register.tag(name='restructuredTextWO')
def restructured_text_without(parser, token):
nodelist = parser.parse(('endrestructuredTextWO',))
parser.delete_first_token()
try:
tag_name, role_name = token.contents.split(None, 1)
except ValueError:
raise template.TemplateSyntaxError(
'%r tag requires an argument' % token.contents.split()[0])
return Without(nodelist, role_name)
class Without(template.Node):
def __init__(self, nodelist, role_name):
if settings.DEBUG:
print 'Without', role_name
self.nodelist = nodelist
self.role_name = role_name
self.role_fn = None
def render(self, context):
from docutils.parsers.rst import roles
self.role_fn = roles._role_registry.pop(self.role_name, None)
output = self.nodelist.render(context)
if self.role_fn:
roles._role_registry[self.role_name] = self.role_fn
return output
In the template I have
<h1 class="blog_header">{{blog.title|capfirst}}</h1>
<h3 class="blog_creation_date">
{{blog.creation_date|date:"D d M Y"}}
</h3>
<div class="blog_content">
{{blog.content|restructuredtext}}
</div>
<h2>Comments</h2>
{% get_comment_list for blog as comments %}
{% for comment in comments %}
{% comment_entry comment %}
{% endfor %}
where comment_entry is a inclusion tag defined as
{% load markup %}
{% restructuredTextWO tex %}
<div class="entry">
<h3>posted by <a href="{{site}}">{{username}}</a>
at {{date|date:"D d M Y"}}</h3>
<p>{{content|restructuredtext}}</p>
</div>
{% endrestructuredTextWO %}
Now, the problem is that this doesn't work if also the blog contains the
:tex: role and I don't understand why: there is something I'm missing in
how the template rendering works?
I would appreciate some hints about that.
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.