diff options
| author | Eric O'Connell <eric.oconnell@idealist.org> | 2011-05-20 16:54:40 -0700 |
|---|---|---|
| committer | Eric O'Connell <eric.oconnell@idealist.org> | 2011-05-20 16:54:40 -0700 |
| commit | cf2648533ca5dcceef6ccf36a55e57b375a9cbb3 (patch) | |
| tree | 6f5bc056cc61370eb995709e6306a2aceab3bd8a | |
| parent | 9474181f3c2efc6bb76d2f3997b746363e28a1b7 (diff) | |
| parent | 606744f10543c90fb1e5e291c447e67eb286f080 (diff) | |
| download | creole-cf2648533ca5dcceef6ccf36a55e57b375a9cbb3.tar.gz | |
Merge remote-tracking branch 'remotes/origin/patch-1'
| -rw-r--r-- | AUTHORS | 3 | ||||
| -rw-r--r-- | README | 8 | ||||
| -rw-r--r-- | creole/__init__.py | 4 | ||||
| -rw-r--r-- | creole/creole2html.py | 48 | ||||
| -rw-r--r-- | creole/creole_parser.py | 9 | ||||
| -rw-r--r-- | creole/default_macros.py | 8 | ||||
| -rw-r--r-- | creole/html2creole.py | 4 | ||||
| -rw-r--r-- | demo.py | 8 | ||||
| -rw-r--r-- | dev_scripts/svn_keywords_client.py | 60 | ||||
| -rw-r--r-- | tests/run_all_tests.py | 5 | ||||
| -rw-r--r-- | tests/test_creole2html.py | 13 | ||||
| -rw-r--r-- | tests/test_cross_compare.py | 29 | ||||
| -rw-r--r-- | tests/test_html2creole.py | 4 | ||||
| -rw-r--r-- | tests/utils/base_unittest.py | 16 | ||||
| -rw-r--r-- | tests/utils/utils.py | 20 |
15 files changed, 75 insertions, 164 deletions
@@ -24,6 +24,3 @@ CONTRIBUTORS are and/or have been (alphabetic order): Special thanks to the python-forum.de guys, particularly (in alphabetic order): * sma -last SVN commit info: - $LastChangedDate$ - $Rev$
\ No newline at end of file @@ -41,6 +41,11 @@ See also: http://github.com/jedie/python-creole/blob/master/demo.py history ========= +- v0.4 + + - only emit children of empty tags like div and span (contributed by Eric O'Connell) + - remove inter wiki links and doen't check the protocol + - v0.3.3 - Use <tt> when {{{ ... }}} is inline and not <pre>, see: http://forum.pylucid.org/viewtopic.php?f=3&t=320 @@ -127,3 +132,6 @@ See also: http://github.com/jedie/python-creole/blob/master/demo.py :PyPi: http://pypi.python.org/pypi/python-creole/ +:flattr this: + http://flattr.com/thing/181554/python-creole + diff --git a/creole/__init__.py b/creole/__init__.py index 93193d1..e077e8e 100644 --- a/creole/__init__.py +++ b/creole/__init__.py @@ -14,10 +14,10 @@ http://pypi.python.org/pypi/python-creole/ :copyleft: 2008-2011 by python-creole team, see AUTHORS for more details. - :license: GNU GPL v3 or above, see LICENSE.txt for more details. + :license: GNU GPL v3 or above, see LICENSE for more details. """ -__version__ = (0, 3, 3)#, "pre") +__version__ = (0, 4, 0)#, "pre") __api__ = (1, 0) # Creole 1.0 spec - http://wikicreole.org/ diff --git a/creole/creole2html.py b/creole/creole2html.py index 84bebea..7129cba 100644 --- a/creole/creole2html.py +++ b/creole/creole2html.py @@ -1,42 +1,29 @@ # coding: utf-8 + """ WikiCreole to HTML converter - @copyright: 2007 MoinMoin:RadomirDopieralski, - 2008-2010 JensDiemer - @license: GNU GPL v3 or above, see LICENSE for details. + :copyleft: 2008-2011 by python-creole team, see AUTHORS for more details. + :license: GNU GPL v3 or above, see LICENSE for more details. """ -import sys, re, traceback + +from xml.sax.saxutils import escape +import re +import sys +import traceback import default_macros from creole_parser import Parser -#from PyLucid.tools.utils import escape -from xml.sax.saxutils import escape - -class Rules: - # For the link targets: - proto = r'http|https|ftp|nntp|news|mailto|telnet|file|irc' - extern = r'(?P<extern_addr>(?P<extern_proto>%s):.*)' % proto - interwiki = r''' - (?P<inter_wiki> [A-Z][a-zA-Z]+ ) : - (?P<inter_page> .* ) - ''' - class HtmlEmitter: """ Generate HTML output for the document tree consisting of DocNodes. """ - addr_re = re.compile('|'.join([ - Rules.extern, - Rules.interwiki, - ]), re.X | re.U) # for addresses - def __init__(self, root, macros=default_macros, verbose=1, stderr=sys.stderr): self.root = root self.macros = macros @@ -52,7 +39,6 @@ class HtmlEmitter: def html_escape(self, text): return escape(text) - #return text.replace('&', '&').replace('<', '<').replace('>', '>') def attr_escape(self, text): return self.html_escape(text).replace('"', '"') @@ -155,28 +141,13 @@ class HtmlEmitter: inside = self.emit_children(node) else: inside = self.html_escape(target) - m = self.addr_re.match(target) - if m: - if m.group('extern_addr'): - return u'<a href="%s">%s</a>' % ( - self.attr_escape(target), inside) - elif m.group('inter_wiki'): - raise NotImplementedError + return u'<a href="%s">%s</a>' % ( self.attr_escape(target), inside) def image_emit(self, node): target = node.content text = self.get_text(node) - m = self.addr_re.match(target) - if m and m.group('inter_wiki'): - raise NotImplementedError - -# if m.group('extern_addr'): -# return u'<img src="%s" alt="%s" />' % ( -# self.attr_escape(target), self.attr_escape(text)) -# -# elif return u'<img src="%s" alt="%s" />' % ( self.attr_escape(target), self.attr_escape(text)) @@ -278,6 +249,7 @@ class HtmlEmitter: # No error output return u"" + if __name__ == "__main__": txt = u"""this is **bold** ok? for example ** this sentence""" diff --git a/creole/creole_parser.py b/creole/creole_parser.py index 874eb33..4a723e2 100644 --- a/creole/creole_parser.py +++ b/creole/creole_parser.py @@ -1,5 +1,6 @@ # coding: utf-8 + """ Creole wiki markup parser @@ -17,13 +18,11 @@ unrecognized schemes (like wtf://server/path) triggering italic rendering for the rest of the paragraph. - - @copyright: 2007 MoinMoin:RadomirDopieralski (creole 0.5 implementation), - 2007 MoinMoin:ThomasWaldmann (updates) - 2008-2011 JensDiemer - @license: GNU GPL v3 or above, see LICENSE for details. + :copyleft: 2008-2011 by python-creole team, see AUTHORS for more details. + :license: GNU GPL v3 or above, see LICENSE for more details. """ + import re diff --git a/creole/default_macros.py b/creole/default_macros.py index 375e7a6..41ea022 100644 --- a/creole/default_macros.py +++ b/creole/default_macros.py @@ -1,12 +1,17 @@ -# -*- coding: utf-8 -*- +# coding: utf-8 + """ Creole macros ~~~~~~~~~~~~~ Note: all mecro functions must return unicode! + + :copyleft: 2008-2011 by python-creole team, see AUTHORS for more details. + :license: GNU GPL v3 or above, see LICENSE for more details. """ + def html(args, text): """ Macro tag <<html>>...<</html>> @@ -15,7 +20,6 @@ def html(args, text): return text - def test_macro(args, text): """ a macro only for testing diff --git a/creole/html2creole.py b/creole/html2creole.py index 7eea45f..8c11a79 100644 --- a/creole/html2creole.py +++ b/creole/html2creole.py @@ -1,5 +1,6 @@ # coding: utf-8 + """ html2creole ~~~~~~~~~~~ @@ -10,6 +11,7 @@ :license: GNU GPL v3 or above, see LICENSE for more details. """ + import re import inspect import warnings @@ -817,7 +819,7 @@ class Html2CreoleEmitter(object): return u"" def _escape_linebreaks(self, text): - test = text.strip() + text = text.strip() text = text.split("\n") lines = [line.strip() for line in text] lines = [line for line in lines if line] @@ -1,13 +1,16 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- +# coding: utf-8 + """ simple demo ~~~~~~~~~~~ """ + from creole import creole2html, html2creole + source = u"""\ == simple demo You can convert from: @@ -23,17 +26,20 @@ You can convert from: More info on our [[http://code.google.com/p/python-creole/|Homepage]].""" + print "*" * 79 print " Source creole markup text:" print "-" * 79 print source + print "*" * 79 print " Convert it into html:" print "-" * 79 html = creole2html(source) print html + print "*" * 79 print " Convert the html code back into creole:" print "-" * 79 diff --git a/dev_scripts/svn_keywords_client.py b/dev_scripts/svn_keywords_client.py deleted file mode 100644 index 298f473..0000000 --- a/dev_scripts/svn_keywords_client.py +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -""" - svn:keywords sync tool - ~~~~~~~~~~~~~~~~~~~~~~ - - usefull tools to automatic setup the SVN keywords. - - Used svn_keyword.py from: - - http://code.google.com/p/python-code-snippets/source/browse/CodeSnippets/svn_keywords.py - or - http://python-code-snippets.googlecode.com/svn/CodeSnippets/svn_keywords.py - - Last commit info: - ~~~~~~~~~~~~~~~~~ - $LastChangedDate:2007-09-22 22:21:14 +0200 (Sa, 22 Sep 2007) $ - $Rev:1244 $ - $Author:JensDiemer $ - - :copyleft: 2008 by the PyLucid team, see AUTHORS for more details. - :license: GNU GPL v3 or above, see LICENSE for more details. -""" - -import sys, os - -os.chdir("../") # go into PyLucid App root folder -print os.getcwd() - -# Path to the svn_keywords.py file: -sys.path.insert(0,"../../python-code-snippets/CodeSnippets/") - -try: - from svn_keywords import Config, cleanup, print_status, sync_keywords -except ImportError, e: - print "Error, can't import svn_keywords.py:" - print e - print - print "(More Information in Doc-String)" - print - sys.exit() - -config = Config -config.repository = "." -config.skip_dirs = ( -) -config.skip_file_ext = (".pyc",".gif", ".png") -#config.simulation = False -config.simulation = True - - -if __name__ == "__main__": -# cleanup(config) - sync_keywords(config) -# print_status(config) - print - print "---END---" - - diff --git a/tests/run_all_tests.py b/tests/run_all_tests.py index ee73966..7b20b0d 100644 --- a/tests/run_all_tests.py +++ b/tests/run_all_tests.py @@ -1,14 +1,16 @@ #!/usr/bin/env python # coding: utf-8 + """ run all unittests ~~~~~~~~~~~~~~~~~ :copyleft: 2008-2011 by python-creole team, see AUTHORS for more details. - :license: GNU GPL v3 or above, see LICENSE.txt for more details. + :license: GNU GPL v3 or above, see LICENSE for more details. """ + import unittest from tests.utils.utils import MarkupTest @@ -16,5 +18,6 @@ from tests.test_cross_compare import CrossCompareTests from tests.test_creole2html import TestCreole2html, TestCreole2htmlMarkup from tests.test_html2creole import TestHtml2Creole, TestHtml2CreoleMarkup + if __name__ == '__main__': unittest.main() diff --git a/tests/test_creole2html.py b/tests/test_creole2html.py index 3191134..2a93507 100644 --- a/tests/test_creole2html.py +++ b/tests/test_creole2html.py @@ -1,6 +1,7 @@ #!/usr/bin/env python # coding: utf-8 + """ creole2html unittest ~~~~~~~~~~~~~~~~~~~~ @@ -13,7 +14,7 @@ Test the creole markup. :copyleft: 2008-2011 by python-creole team, see AUTHORS for more details. - :license: GNU GPL v3 or above, see LICENSE.txt for more details. + :license: GNU GPL v3 or above, see LICENSE for more details. """ @@ -460,16 +461,6 @@ class TestCreole2htmlMarkup(BaseCreoleTest): ...and <tt><strong>strong</strong> Teletyper</tt> ;)</p> """) - def test_upcase_url(self): - """ - FIXME: remove inter wiki stuff??? - """ - self.assertCreole(r""" - [[Http://www.domain.tld|test]] - """, """ - <a href="Http://www.domain.tld">test</a> - """) - if __name__ == '__main__': diff --git a/tests/test_cross_compare.py b/tests/test_cross_compare.py index e655ab1..fb495bc 100644 --- a/tests/test_cross_compare.py +++ b/tests/test_cross_compare.py @@ -1,5 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- +# coding: utf-8 + """ cross compare unittest @@ -11,16 +12,11 @@ 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 - Last commit info: - ~~~~~~~~~~~~~~~~~ - $LastChangedDate$ - $Rev$ - $Author$ - :copyleft: 2008-2009 by python-creole team, see AUTHORS for more details. - :license: GNU GPL v3 or above, see LICENSE.txt for more details. + :license: GNU GPL v3 or above, see LICENSE for more details. """ + import unittest from tests.utils.base_unittest import BaseCreoleTest @@ -87,26 +83,25 @@ class CrossCompareTests(BaseCreoleTest): no __ underline</p> """, debug=False) - def test_internal_links(self): + def test_links(self): self.assertCreole(r""" A [[internal]] link... ...and [[/a internal]] link. - """, """ - <p>A <a href="internal">internal</a> link...<br /> - ...and <a href="/a internal">/a internal</a> link.</p> - """) - - def test_external_links(self): - self.assertCreole(r""" + With pipe separator: 1 [[internal links|link A]] test. 2 [[http://domain.tld|link B]] test. 3 [[http://de.wikipedia.org/wiki/Creole_(Markup)|Creole@wikipedia]] + 4 [[Foo://bar|unknown protocol]] """, """ + <p>A <a href="internal">internal</a> link...<br /> + ...and <a href="/a internal">/a internal</a> link.</p> + <p>With pipe separator:<br /> 1 <a href="internal links">link A</a> test.<br /> 2 <a href="http://domain.tld">link B</a> test.<br /> - 3 <a href="http://de.wikipedia.org/wiki/Creole_(Markup)">Creole@wikipedia</a></p> + 3 <a href="http://de.wikipedia.org/wiki/Creole_(Markup)">Creole@wikipedia</a><br /> + 4 <a href="Foo://bar">unknown protocol</a></p> """) def test_bolditalic_links(self): diff --git a/tests/test_html2creole.py b/tests/test_html2creole.py index d73b879..e0922cd 100644 --- a/tests/test_html2creole.py +++ b/tests/test_html2creole.py @@ -1,6 +1,7 @@ #!/usr/bin/env python # coding: utf-8 + """ html2creole tests ~~~~~~~~~~~~~~~~~ @@ -9,9 +10,10 @@ :copyleft: 2008-2011 by python-creole team, see AUTHORS for more details. - :license: GNU GPL v3 or above, see LICENSE.txt for more details. + :license: GNU GPL v3 or above, see LICENSE for more details. """ + import sys import unittest diff --git a/tests/utils/base_unittest.py b/tests/utils/base_unittest.py index fe99306..2c0856d 100644 --- a/tests/utils/base_unittest.py +++ b/tests/utils/base_unittest.py @@ -1,4 +1,5 @@ -# -*- coding: utf-8 -*- +# coding: utf-8 + """ unitest base class @@ -6,16 +7,11 @@ Basic unittest class for all python-creole tests. - Last commit info: - ~~~~~~~~~~~~~~~~~ - $LastChangedDate:$ - $Rev:$ - $Author$ - :copyleft: 2008-2009 by python-creole team, see AUTHORS for more details. - :license: GNU GPL v3 or above, see LICENSE.txt for more details. + :license: GNU GPL v3 or above, see LICENSE for more details. """ + import sys import unittest @@ -35,10 +31,10 @@ class BaseCreoleTest(MarkupTest): text = text.replace("\t", "\\t") print - print "_"*79 + print "_" * 79 print " Debug Text: %s" % msg print text - print "-"*79 + print "-" * 79 def assert_Creole2html(self, source_string, should_string, \ verbose=1, stderr=sys.stderr, debug=False): diff --git a/tests/utils/utils.py b/tests/utils/utils.py index 3344fd6..74cf7f1 100644 --- a/tests/utils/utils.py +++ b/tests/utils/utils.py @@ -1,4 +1,5 @@ -# -*- coding: utf-8 -*- +# coding: utf-8 + """ unitest generic utils @@ -6,16 +7,11 @@ Generic utils useable for a markup test. - Last commit info: - ~~~~~~~~~~~~~~~~~ - $LastChangedDate:$ - $Rev:$ - $Author$ - :copyleft: 2008-2009 by python-creole team, see AUTHORS for more details. - :license: GNU GPL v3 or above, see LICENSE.txt for more details. + :license: GNU GPL v3 or above, see LICENSE for more details. """ + import sys import difflib import unittest @@ -86,7 +82,7 @@ class MarkupDiffFailure(Exception): # print repr(msg) first_quote = msg[0] - second_quote = msg[-1] + second_quote = msg[-1] #print "quote chars: [%s] [%s]" % (first_quote, second_quote) split_string = "%s != %s" % (first_quote, second_quote) @@ -162,13 +158,13 @@ class MarkupTest(unittest.TestCase): """ txt = unicode(txt) txt = txt.splitlines() - assert txt[0]=="", "First must be empty!" + assert txt[0] == "", "First must be empty!" txt = txt[1:] # Skip the first line # get the indentation level from the first line count = False for count, char in enumerate(txt[0]): - if char!=" ": + if char != " ": break assert count != False, "second line is empty!" @@ -238,4 +234,4 @@ if __name__ == '__main__': doctest.testmod() print "doc test done." - unittest.main()
\ No newline at end of file + unittest.main() |
