Skip to content

Commit

Permalink
Added a reStructuredText processor
Browse files Browse the repository at this point in the history
  • Loading branch information
honzakral committed Nov 15, 2009
1 parent f66be20 commit 1b98f67
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
9 changes: 9 additions & 0 deletions djangomarkup/fixtures/initial_data.json
Expand Up @@ -16,5 +16,14 @@
"processor_options": "",
"name": "czechtile"
}
},
{
"pk": 2,
"model": "djangomarkup.textprocessor",
"fields": {
"function": "djangomarkup.processors.rest",
"processor_options": "",
"name": "rest"
}
}
]
10 changes: 10 additions & 0 deletions djangomarkup/processors.py
Expand Up @@ -29,3 +29,13 @@ def czechtile(src, **kwargs):
return expand(tree, 'xhtml11', expander_map)
except Exception, err:
raise ProcessorError(err)

def rest(src, **kwargs):
try:
from docutils.core import publish_parts
except ImportError:
raise ProcessorConfigurationError(u"docutils not found")

parts = publish_parts(src, writer_name='html', **kwargs)
return parts['fragment']

11 changes: 11 additions & 0 deletions tests/unit_project/test_preview.py
Expand Up @@ -9,6 +9,8 @@ def setUp(self):
self.mock_text = u"beer - 啤酒"
self.czechtile_text = u"= Text =\n češťoučký texďýčšek"
self.czechtile_text_transformed = u"<h1>Text</h1><p>češťoučký texďýčšek</p>"
self.rest_text = u"Text:\n * češťoučký texďýčšek"
self.rest_text_transformed = u'<dl class="docutils">\n<dt>Text:</dt>\n<dd><ul class="first last simple">\n<li>češťoučký texďýčšek</li>\n</ul>\n</dd>\n</dl>\n'

def test_success_default_markdown(self):
self.assert_equals(u"<p>%s</p>" % self.mock_text, self.client.post(reverse("markup-transform"), {'text' : self.mock_text}).content.strip().decode('utf-8'))
Expand All @@ -19,6 +21,15 @@ def test_get_returns_bad_method(self):
def test_empty_(self):
self.assert_equals(u"<p>%s</p>" % self.mock_text, self.client.post(reverse("markup-transform"), {'text' : self.mock_text}).content.strip().decode('utf-8'))

def test_success_rest(self):
try:
import docutils
except ImportError:
raise self.SkipTest("Docutils not installed, skipping")
self.assert_equals(self.rest_text_transformed,
self.client.post(reverse("markup-transform", kwargs={'syntax_processor_name' : "rest"}),
{'text' : self.rest_text}).content.decode('utf-8')
)
def test_success_czechtile(self):
try:
import czechtile
Expand Down

0 comments on commit 1b98f67

Please sign in to comment.