Skip to content
This repository has been archived by the owner on Jan 25, 2019. It is now read-only.

Commit

Permalink
Add textile and markdown2 renderers.
Browse files Browse the repository at this point in the history
Closes #76.
  • Loading branch information
mythmon committed May 9, 2012
1 parent 1f51fd4 commit 78d59fd
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 12 deletions.
15 changes: 9 additions & 6 deletions docs/content/docs/content.mkd
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
title: Content
category: docs
---
Content can be written in various markup languages (currently [Markdown][mkd] or [reStructuredText][rst]), with a
[YAML][yaml] header, separated by 3 hyphens alone on a line. For example:

[mkd]: http://daringfireball.net/projects/markdown/
[rst]: http://docutils.sourceforge.net/rst.html
[yaml]: http://www.yaml.org/
Content can be written in various markup languages (currently [Markdown][mkd],
[reStructuredText][rst], and [Textile][]), with a [YAML][yaml] header, separated by 3 hyphens
alone on a line. For example:

::text
title: Sample Post
Expand All @@ -20,6 +17,12 @@ Content can be written in various markup languages (currently [Markdown][mkd] or
ligula porta vestibulum et ut sem. Cras hendrerit pulvinar metus at
imperdiet.

[mkd]: http://daringfireball.net/projects/markdown/
[rst]: http://docutils.sourceforge.net/rst.html
[textile]: http://textile.sitemonks.com/
[yaml]: http://www.yaml.org/


Metadata
--------
These are the variables that affect the rending, layout, and categorization of pages in the YAML metadata.
Expand Down
58 changes: 52 additions & 6 deletions wok/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,15 @@ def render(cls, plain):

# Include markdown, if it is available.
try:
from markdown import markdown
# Try to get the faster cMarkdown
try:
from cMarkdown import markdown
except ImportError:
from markdown import markdown

class Markdown(Renderer):
"""Markdown renderer."""
extensions = ['markdown', 'mkd']
extensions = ['markdown', 'mkd', 'md']

plugins = ['def_list', 'footnotes']
if have_pygments:
Expand All @@ -48,7 +53,29 @@ def render(cls, plain):
all.append(Markdown)

except ImportError:
logging.info('Markdown not enabled.')
logging.debug("markdown isn't available, trying markdown2")
markdown = None

# Try Markdown2
if markdown is None:
try:
import markdown2
class Markdown(Renderer):
"""Markdown2 renderer."""
extensions = ['markdown', 'mkd', 'md']

extras = ['def_list', 'footnotes']
if have_pygments:
extras.append('fenced-code-blocks')

@classmethod
def render(cls, plain):
return markdown2.markdown(plain, extras=extras)

all.append(Markdown2)
except:
logging.info('Markdown not enabled.')


# Include ReStructuredText Parser, if we have docutils
try:
Expand All @@ -74,7 +101,26 @@ def render(cls, plain):
except:
logging.info('reStructuredText not enabled.')


# Try Textile
try:
import textile
class Textile(Renderer):
"""Textile renderer."""
extensions = ['textile']

@classmethod
def render(cls, plain):
return textile.textile(plain)

all.append(Markdown2)
except:
logging.info('Markdown not enabled.')



if len(all) <= 2:
print('You probably want to install either Markdown or docutils '
'(reStructuredText). Otherwise only plain text input will be '
'supported.')
print("You probably want to install either a Markdown library (one of "
"'Markdown', or 'markdown2'), 'docutils' (for reStructuredText), or "
"'textile'. Otherwise only plain text input will be supported. You "
"can install any of these like 'sudo pip install PACKAGE'.")

0 comments on commit 78d59fd

Please sign in to comment.