Skip to content

Commit

Permalink
Merge branch 'feature/markdown-extensions' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Fantomas42 committed Apr 17, 2015
2 parents e2d1feb + 4f3bb7f commit 9b82fb4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
9 changes: 5 additions & 4 deletions docs/ref/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,13 @@ You can use one of these values: ::

ZINNIA_MARKDOWN_EXTENSIONS
--------------------------
**Default value:** ``''`` (Empty string)
**Default value:** ``()`` (Empty tuple)

Extensions names coma separated to be used for rendering the entries in
MarkDown. Example: ::
List of either markdown.Extension instances or extension paths, used for
rendering the entries in MarkDown. Example: ::

ZINNIA_MARKDOWN_EXTENSIONS = 'extension1_name,extension2_name...'
ZINNIA_MARKDOWN_EXTENSIONS = ['markdown.extensions.nl2br',
MyExtension(mysetting="foo")]

.. setting:: ZINNIA_RESTRUCTUREDTEXT_SETTINGS

Expand Down
5 changes: 3 additions & 2 deletions zinnia/markups.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def markdown(value, extensions=MARKDOWN_EXTENSIONS):
"""
Markdown processing with optionally using various extensions
that python-markdown supports.
`extensions` is an iterable of either markdown.Extension instances
or extension paths.
"""
try:
import markdown
Expand All @@ -38,9 +40,8 @@ def markdown(value, extensions=MARKDOWN_EXTENSIONS):
RuntimeWarning)
return value

extensions = [e for e in extensions.split(',') if e]
return markdown.markdown(force_text(value),
extensions, safe_mode=False)
extensions=extensions, safe_mode=False)


def restructuredtext(value, settings=RESTRUCTUREDTEXT_SETTINGS):
Expand Down
4 changes: 2 additions & 2 deletions zinnia/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

MARKUP_LANGUAGE = getattr(settings, 'ZINNIA_MARKUP_LANGUAGE', 'html')

MARKDOWN_EXTENSIONS = getattr(settings, 'ZINNIA_MARKDOWN_EXTENSIONS', '')
MARKDOWN_EXTENSIONS = getattr(settings, 'ZINNIA_MARKDOWN_EXTENSIONS', [])

RESTRUCTUREDTEXT_SETTINGS = getattr(
settings, 'ZINNIA_RESTRUCTUREDTEXT_SETTINGS', {})
Expand Down Expand Up @@ -83,7 +83,7 @@
'excerpt', 'image_caption'])

SPAM_CHECKER_BACKENDS = getattr(settings, 'ZINNIA_SPAM_CHECKER_BACKENDS',
())
[])

URL_SHORTENER_BACKEND = getattr(settings, 'ZINNIA_URL_SHORTENER_BACKEND',
'zinnia.url_shortener.backends.default')
11 changes: 10 additions & 1 deletion zinnia/tests/test_markups.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,21 @@ def test_markdown_extensions(self):
self.assertEqual(markdown(text).strip(),
'<p>[TOC]</p>\n<h1>Header 1</h1>'
'\n<h2>Header 2</h2>')
self.assertEqual(markdown(text, extensions='toc').strip(),
self.assertEqual(markdown(text, extensions=['toc']).strip(),
'<div class="toc">\n<ul>\n<li><a href="#header-1">'
'Header 1</a><ul>\n<li><a href="#header-2">'
'Header 2</a></li>\n</ul>\n</li>\n</ul>\n</div>'
'\n<h1 id="header-1">Header 1</h1>\n'
'<h2 id="header-2">Header 2</h2>')
from markdown.extensions.toc import TocExtension
tocext = TocExtension(marker='--TOC--', permalink='PL')
self.assertEqual(markdown(text, extensions=[tocext]).strip(),
'<p>[TOC]</p>\n<h1 id="header-1">Header 1'
'<a class="headerlink" href="#header-1" '
'title="Permanent link">PL</a></h1>\n'
'<h2 id="header-2">Header 2'
'<a class="headerlink" href="#header-2" '
'title="Permanent link">PL</a></h2>')

@skipUnless(is_lib_available('docutils'), 'Docutils is not available')
def test_restructuredtext(self):
Expand Down

0 comments on commit 9b82fb4

Please sign in to comment.