#!/usr/bin/env python # coding: utf-8 """ html2creole tests ~~~~~~~~~~~~~~~~~ special html to creole convert tests, witch can't tests in "cross compare" :copyleft: 2008-2011 by python-creole team, see AUTHORS for more details. :license: GNU GPL v3 or above, see LICENSE for more details. """ import unittest from creole import html2creole from creole.shared.unknown_tags import ( escape_unknown_nodes, raise_unknown_node, transparent_unknown_nodes, use_html_macro, ) from creole.tests.utils.base_unittest import BaseCreoleTest class TestHtml2Creole(unittest.TestCase): """ Tests around html2creole API. """ pass class TestHtml2CreoleMarkup(BaseCreoleTest): # def assertCreole(self, raw_markup, raw_html, debug=False, **kwargs): # self.assert_html2creole(raw_markup, raw_html, debug=debug, **kwargs) # -------------------------------------------------------------------------- def test_not_used(self): """ Some other html tags -> convert. """ self.assert_html2creole(r""" **Bold text** **Big text** //em tag// //italic// """, """

Bold text
Big text
em tag
italic

""") # -------------------------------------------------------------------------- def test_raise_unknown_node(self): """ Test creole.html2creole.raise_unknown_node callable: Raise NotImplementedError on unknown tags. """ self.assertRaises(NotImplementedError, html2creole, html_string="", unknown_emit=raise_unknown_node ) def test_use_html_macro(self): """ Test creole.html2creole.use_html_macro callable: Use the <> macro to mask unknown tags. """ self.assert_html2creole(r""" 111 <><>foo<><> 222 333<><>foobar<><>444 555<><>666 """, """

111 foo 222
333foobar444

555666

""", unknown_emit=use_html_macro ) def test_escape_unknown_nodes(self): """ Test creole.html2creole.escape_unknown_nodes callable: All unknown tags should be escaped. """ self.assert_html2creole(r""" 111 <unknown>foo</unknown> 222 333<unknown foo1="bar1" foo2="bar2">foobar</unknown>444 555<unknown />666 """, """

111 foo 222
333foobar444

555666

""", unknown_emit=escape_unknown_nodes ) def test_escape_unknown_nodes2(self): """ HTMLParser has problems with """, unknown_emit=escape_unknown_nodes ) def test_transparent_unknown_nodes(self): """ Test creole.html2creole.transparent_unknown_nodes callable: All unknown tags should be "transparent" and show only their child nodes' content. """ self.assert_html2creole(r""" //baz//, **quux** """, """
, quux
""", unknown_emit=transparent_unknown_nodes ) def test_transparent_unknown_nodes2(self): """ HTMLParser has problems with BAR

""", unknown_emit=transparent_unknown_nodes ) def test_transparent_unknown_nodes_block_elements(self): """ Test that block elements insert linefeeds into the stream. """ self.assert_html2creole(r""" //baz//, **quux** spam, ham, and eggs """, """
baz,
quux
spam, and eggs """, unknown_emit=transparent_unknown_nodes ) # -------------------------------------------------------------------------- def test_entities(self): """ Test html entities. copyright sign is in Latin-1 Supplement: http://pylucid.org/_command/144/DecodeUnicode/display/1/ Box Drawing: http://pylucid.org/_command/144/DecodeUnicode/display/66/ """ self.assert_html2creole(""" * less-than sign: < < < * greater-than sign: > > > * copyright sign: © © * box drawing: ╬ ╬ * german umlauts: ä ö ü """, """ """) def test_html_entity_nbsp(self): """ Non breaking spaces is not in htmlentitydefs """ self.assert_html2creole(r""" a non braking space: [ ] ! """, """

a non braking space: [ ] !

""") def test_html_entity_in_pre(self): self.assert_html2creole(r""" {{{{% lucidTag RSS url="http url" %}}}} """, """
{% lucidTag RSS url="http url" %}
""") def test_unknown_entity(self): """ Test a unknown html entity. FIXME: What sould happend? """ self.assert_html2creole(r""" copy&paste """, """

copy&paste

""") self.assert_html2creole(r""" [[/url/|Search & Destroy]] """, """ Search & Destroy """) def test_tbody_table(self): self.assert_html2creole(r""" Ignore 'tbody' tag in tables: |= Headline 1 |= Headline 2 | | cell one | cell two | end """, """

Ignore 'tbody' tag in tables:

Headline 1 Headline 2
cell one cell two

end

""") def test_p_table(self): """ strip

tags in table cells """ self.assert_html2creole(r""" | cell one | cell two\\new line | """, """

cell one

cell two

new line

""") def test_image(self): """ test image tag with different alt/title attribute """ self.assert_html2creole(r""" {{foobar1.jpg|foobar1.jpg}} {{/foobar2.jpg|foobar2.jpg}} {{/path1/path2/foobar3.jpg|foobar3.jpg}} {{/foobar4.jpg|It's foobar 4}} {{/foobar5.jpg|It's foobar 5}} {{/foobar6.jpg|a long picture title}} """, """




It's foobar 4

short name
data uri should be disallowed

""") def test_image_with_size(self): """ test image tag with sizes """ self.assert_html2creole(r""" {{foobar1.jpg|foobar1.jpg}} {{foobar2.jpg|foobar2.jpg|90x160}} {{foobar3.jpg|foobar3.jpg}} """, """



""") def test_image_with_size_strict(self): """ test image tag with sizes """ self.assert_html2creole(r""" {{foobar1.jpg|foobar1.jpg}} {{foobar2.jpg|foobar2.jpg}} {{foobar3.jpg|foobar3.jpg}} """, """



""", strict=True) def test_non_closed_br(self): self.assert_html2creole(r""" one two """, """

one
two

""") def test_explicit_closed_br(self): self.assert_html2creole(r""" one two """, """

one

two

""") def test_newline_before_list(self): """ http://code.google.com/p/python-creole/issues/detail?id=16 """ self.assert_html2creole(r""" **foo** * one """, """ foo """) def test_empty_tags_are_not_escaped(self): self.assert_html2creole(r""" //baz//, **quux** """, """
baz, quux
""") def test_nested_listsitems_with_paragraph(self): self.assert_html2creole(""" * item 1 ** subitem 1.1 *** subsubitem 1.1.1 *** subsubitem 1.1.2 ** subitem 1.2 * item 2 ** subitem 2.1 """, """ """) def test_class_in_list(self): """https://code.google.com/p/python-creole/issues/detail?id=19#c4""" self.assert_html2creole(r""" # foo """, """
  1. foo
""") # , debug=True) def test_ignore_links_without_href(self): """https://code.google.com/p/python-creole/issues/detail?id=19#c4""" self.assert_html2creole(r""" bar """, """ bar """) # , debug=True) def test_newlines_after_headlines(self): self.assert_html2creole(r""" = Headline news [[http://google.com|The googlezor]] is a big bad mother. """, """

Headline news

The googlezor is a big bad mother.

""") def test_links(self): self.assert_html2creole(r""" test link: '[[internal links|link A]]' 1 and test link: '[[http://domain.tld|link B]]' 2. """, """

test link: 'link A' 1 and
test link: 'link B' 2.

""") def test_horizontal_rule(self): self.assert_html2creole(r""" one ---- two """, """

one


two

""") def test_nested_empty_tags(self): self.assert_html2creole2("TEST", "

TEST

") self.assert_html2creole2("TEST", "

TEST

") self.assert_html2creole2("TEST", "

TEST

") # def test_nowiki1(self): # self.assert_html2creole(r""" # this: # {{{ # //This// does **not** get [[formatted]] # }}} # and this: {{{** this ** }}} not, too. # # === Closing braces in nowiki: # {{{ # if (x != NULL) { # for (i = 0; i < size; i++) { # if (x[i] > 0) { # x[i]--; # }}} # }}} # """, """ #

this:

#
#            //This// does **not** get [[formatted]]
#            
#

and this: ** <i>this</i> ** not, too.

# #

Closing braces in nowiki:

#
#            if (x != NULL) {
#              for (i = 0; i < size; i++) {
#                if (x[i] > 0) {
#                  x[i]--;
#              }}}
#            
# """) # # def test_list1(self): # """ # FIXME: Two newlines between a list and the next paragraph :( # """ # self.assert_html2creole(r""" # ==== List a: # * a1 item # ** a1.1 Force\\linebreak # ** a1.2 item # *** a1.2.1 item # *** a1.2.2 item # * a2 item # # # list 'a' end # # ==== List b: # # b1 item # ## b1.2 item # ### b1.2.1 item # ### b1.2.2 Force\\linebreak1\\linebreak2 # ## b1.3 item # # b2 item # # # list 'b' end # """, """ #

List a:

# #

list 'a' end

# #

List b:

#
    #
  1. b1 item
  2. #
      #
    1. b1.2 item
    2. #
        #
      1. b1.2.1 item
      2. #
      3. b1.2.2 Force # linebreak1 # linebreak2
      4. #
      #
    3. b1.3 item
    4. #
    #
  3. b2 item
  4. #
#

list 'b' end

# """, # debug=True # ) # # def test_list2(self): # """ Bold, Italics, Links, Pre in Lists """ # self.assert_html2creole(r""" # * **bold** item # * //italic// item # # # item about a [[domain.tld|page link]] # # {{{ //this// is **not** [[processed]] }}} # """, """ # #
    #
  1. item about a page link
  2. #
  3. //this// is **not** [[processed]]
  4. #
# """, # debug=True # ) if __name__ == '__main__': unittest.main( # defaultTest="TestHtml2CreoleMarkup.test_nested_listsitems_with_paragraph" )