Commit d0047006 by benjaoming

Merge branch 'master' of github.com:benjaoming/django-wiki

parents b3365861 365793db
......@@ -5,7 +5,8 @@ from django.utils.translation import ugettext as _
from django.template.loader import render_to_string
from django.template import Context
MACRO_RE = re.compile(r'.*(\[(?P<macro>\w+)(\:(?P<arg>\w+))?\]).*', re.IGNORECASE)
MACRO_RE = re.compile(r'.*(\[(?P<macro>\w+)(?P<kwargs>\s\w+\:.+)*\]).*', re.IGNORECASE)
KWARG_RE = re.compile(r'([^ |:]+):([^ |$]+)', re.IGNORECASE)
from wiki.plugins.macros import settings
......@@ -19,7 +20,7 @@ class MacroExtension(markdown.Extension):
class MacroPreprocessor(markdown.preprocessors.Preprocessor):
"""django-wiki macro preprocessor - parse text for various [some_macro] and
[some_macro:arg] references. """
[some_macro (kw:arg)*] references. """
allowed_methods = settings.METHODS
......@@ -31,22 +32,22 @@ class MacroPreprocessor(markdown.preprocessors.Preprocessor):
macro = m.group('macro').strip()
if not macro in MacroPreprocessor.allowed_methods:
continue
arg = m.group('arg')
if arg:
arg = arg.strip()
try:
line = getattr(self, macro)(arg)
except AttributeError:
pass
kwargs = m.group('kwargs')
if kwargs:
kwargs = eval('{' + KWARG_RE.sub(r'"\1":"\2",', kwargs) + '}')
line = getattr(self, macro)(**kwargs)
else:
line = getattr(self, macro)()
if not line is None:
new_text.append(line)
return new_text
def article_list(self, arg=None):
def article_list(self, depth=2):
html = render_to_string(
"wiki/plugins/macros/article_list.html",
Context({
'article_children': self.markdown.article.get_children,
'depth': int(depth) + 1,
})
)
return self.markdown.htmlStash.store(html, safe=True)
......
......@@ -5,7 +5,7 @@
<h3>{% trans "Articles" %}</h3>
<br/>
{% for child in article_children %}
{% article_list child %}
{% article_list child depth %}
{% endfor %}
</div>
{% endif %}
......@@ -2,11 +2,11 @@
{% load url from future %}
<p><a href="{% url 'wiki:get' path=parent.path article_id=parent.article.id %}">{{ parent.article }}</a></p>
{% if parent.children.count %}
{% if parent.children.count and parent.level < depth %}
<div class="wiki-article-sublist">
<ul>
{% for child in parent.children.all %}
<li>{% article_list child %}</li>
<li>{% article_list child depth %}</li>
{% endfor %}
</ul>
</div>
......
......@@ -8,8 +8,9 @@ register = template.Library()
'wiki/plugins/templatetags/article_list.html',
takes_context=True
)
def article_list(context, urlpath):
def article_list(context, urlpath, depth):
context['parent'] = urlpath
context['depth'] = depth
return context
......@@ -21,4 +22,4 @@ def allowed_macros():
except AttributeError:
continue
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment