Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* Change version string to v0.5, because API changed

* update README
* add a unittest for \"use_html_macro\" callable
* update 'cross compage' unittests (newline after headline)
* some code cleanup
  • Loading branch information...
commit 8e0c796530a5bd5174d053e31b96d883bba86d02 1 parent 7566b9b
@jedie authored
View
4 README
@@ -41,6 +41,10 @@ See also: http://github.com/jedie/python-creole/blob/master/demo.py
history
=========
+- v0.5
+
+ - API changed: Html2CreoleEmitter optinal argument 'unknown_emit' taks now a callable for handle unknown html tags.
+
- v0.4
- only emit children of empty tags like div and span (contributed by Eric O'Connell)
View
5 creole/__init__.py
@@ -1,5 +1,6 @@
# coding: utf-8
+
"""
python-creole
~~~~~~~~~~~~~
@@ -17,7 +18,8 @@
:license: GNU GPL v3 or above, see LICENSE for more details.
"""
-__version__ = (0, 4, 1, "pre")
+
+__version__ = (0, 5, 0, "pre")
__api__ = (1, 0) # Creole 1.0 spec - http://wikicreole.org/
@@ -30,6 +32,7 @@
from html2creole import raise_unknown_node, use_html_macro, \
escape_unknown_nodes, transparent_unknown_nodes
+
try:
from django.utils.version import get_svn_revision
except ImportError:
View
17 creole/html2creole.py
@@ -557,14 +557,19 @@ def replace_entity(match):
def raise_unknown_node(emitter, node):
"""
+ unknown_emit callable for Html2CreoleEmitter
+
Raise NotImplementedError on unknown tags.
"""
raise NotImplementedError(
"Node from type '%s' is not implemented!" % node.kind
)
+
def use_html_macro(emitter, node):
"""
+ unknown_emit callable for Html2CreoleEmitter
+
Use the <<html>> macro to mask unknown tags.
"""
attrs = node.get_attrs_as_string()
@@ -586,8 +591,11 @@ def use_html_macro(emitter, node):
return start_tag + content + end_tag
+
def escape_unknown_nodes(emitter, node):
"""
+ unknown_emit callable for Html2CreoleEmitter
+
All unknown tags should be escaped.
"""
attrs = node.get_attrs_as_string()
@@ -609,7 +617,14 @@ def escape_unknown_nodes(emitter, node):
return start_tag + content + end_tag
+
def transparent_unknown_nodes(emitter, node):
+ """
+ unknown_emit callable for Html2CreoleEmitter
+
+ Remove all unknown html tags and show only
+ their child nodes' content.
+ """
return emitter._emit_content(node)
@@ -866,7 +881,7 @@ def emit_node(self, node):
content = emit_method(node)
else:
content = self._unknown_emit(self, node)
-
+
if not isinstance(content, unicode):
raise AssertionError(
"Method '%s' returns no unicode (returns: %r)" % (
View
21 tests/test_cross_compare.py
@@ -12,7 +12,7 @@
Note: This only works fine if there is no problematic whitespace handling.
In this case, we must test in test_creole2html.py or test_html2creole.py
- :copyleft: 2008-2009 by python-creole team, see AUTHORS for more details.
+ :copyleft: 2008-2011 by python-creole team, see AUTHORS for more details.
:license: GNU GPL v3 or above, see LICENSE for more details.
"""
@@ -21,9 +21,6 @@
from tests.utils.base_unittest import BaseCreoleTest
-from creole.html2creole import RAISE_UNKNOWN_NODES, HTML_MACRO_UNKNOWN_NODES, \
- ESCAPE_UNKNOWN_NODES
-
class CrossCompareTests(BaseCreoleTest):
"""
@@ -135,6 +132,7 @@ def test_image(self):
def test_pre_contains_braces(self):
self.assertCreole(r"""
=== Closing braces in nowiki:
+
{{{
if (x != NULL) {
for (i = 0; i < size; i++) {
@@ -144,6 +142,7 @@ def test_pre_contains_braces(self):
}}}
""", """
<h3>Closing braces in nowiki:</h3>
+
<pre>
if (x != NULL) {
for (i = 0; i &lt; size; i++) {
@@ -217,21 +216,35 @@ def test_tt(self):
def test_headlines(self):
self.assertCreole(r"""
= Level 1 (largest)
+
== Level 2
+
=== Level 3
+
==== Level 4
+
===== Level 5
+
====== Level 6
+
=== **not** \\ //parsed//
+
No == headline == or?
""", r"""
<h1>Level 1 (largest)</h1>
+
<h2>Level 2</h2>
+
<h3>Level 3</h3>
+
<h4>Level 4</h4>
+
<h5>Level 5</h5>
+
<h6>Level 6</h6>
+
<h3>**not** \\ //parsed//</h3>
+
<p>No == headline == or?</p>
""")
View
31 tests/test_html2creole.py
@@ -56,6 +56,8 @@ def test_not_used(self):
<i>italic</i></p>
""")
+ #--------------------------------------------------------------------------
+
def test_raise_unknown_node(self):
"""
Test creole.html2creole.raise_unknown_node callable:
@@ -67,6 +69,25 @@ def test_raise_unknown_node(self):
unknown_emit=raise_unknown_node
)
+ def test_use_html_macro(self):
+ """
+ Test creole.html2creole.use_html_macro callable:
+ Use the <<html>> macro to mask unknown tags.
+ """
+ self.assertCreole(r"""
+ 111 <<html>><unknown><</html>>foo<<html>></unknown><</html>> 222
+ 333<<html>><unknown foo1="bar1" foo2="bar2"><</html>>foobar<<html>></unknown><</html>>444
+
+ 555<<html>><unknown /><</html>>666
+ """, """
+ <p>111 <unknown>foo</unknown> 222<br />
+ 333<unknown foo1="bar1" foo2="bar2">foobar</unknown>444</p>
+
+ <p>555<unknown />666</p>
+ """,
+ unknown_emit=use_html_macro
+ )
+
def test_escape_unknown_nodes(self):
"""
Test creole.html2creole.escape_unknown_nodes callable:
@@ -85,7 +106,7 @@ def test_escape_unknown_nodes(self):
""",
unknown_emit=escape_unknown_nodes
)
-
+
def test_transparent_unknown_nodes(self):
"""
Test creole.html2creole.transparent_unknown_nodes callable:
@@ -96,7 +117,7 @@ def test_transparent_unknown_nodes(self):
//baz//, **quux**
""", """
<form class="foo" id="bar"><label><em>baz</em></label>, <strong>quux</strong></form>
- """, unknown_emit = transparent_unknown_nodes)
+ """, unknown_emit=transparent_unknown_nodes)
def test_transparent_unknown_nodes_block_elements(self):
"""
@@ -111,8 +132,10 @@ def test_transparent_unknown_nodes_block_elements(self):
""", """
<div><em>baz</em>,</div> <fieldset><strong>quux</strong></fieldset>
<span>spam, </span><label>ham, </label>and eggs
- """, unknown_emit = transparent_unknown_nodes)
-
+ """, unknown_emit=transparent_unknown_nodes)
+
+ #--------------------------------------------------------------------------
+
def test_entities(self):
"""
Test html entities.
Please sign in to comment.
Something went wrong with that request. Please try again.