Anonymous avatar Anonymous committed 060777f

[svn] o fixed markdown. whitespace
o removed unused auto_link_email_addresses internal function
o added small textilize and markdown tests

Comments (0)

Files changed (2)

tests/test_text.py

         self.assertEqual("Hello World!", truncate("Hello World!", 12))
         self.assertEqual("Hello Wor...", truncate("Hello World!!", 12))
 
+    def test_textilize(self):
+        self.assertEqual('<h1>This is a test of textile</h1>\n\n<p>Paragraph</p>\n\n<p>Another paragraph</p>\n\n<ul>\n<li>Bullets</li>\n</ul>',
+                         textilize("h1. This is a test of textile\n\nParagraph\n\nAnother paragraph\n\n* Bullets"))
+
+    def test_markdown(self):
+        markdown_text = """
+Introduction
+------------
+
+Markdown is a text-to-HTML conversion tool for web writers.
+
+Acknowledgements <a id="acknowledgements" />
+----------------
+
+[Michel Fortin][] has ported to Markdown to PHP.
+        """
+        self.assertEqual('\n\n<h2>Introduction</h2>\n<p>Markdown is a text-to-HTML conversion tool for web writers.\n</p>\n\n<h2>Acknowledgements <a id="acknowledgements" /></h2>\n<p>[Michel Fortin][] has ported to Markdown to PHP.\n</p>\n\n\n',
+                         markdown(markdown_text))
+
 if __name__ == '__main__':
     suite = [unittest.makeSuite(TestTextHelper)]
     for testsuite in suite:

webhelpers/rails/text.py

 import textwrap
 import warnings
 import webhelpers.textile as textile
-import webhelpers.markdown as markdown
+import webhelpers.markdown as _markdown
 from routes import request_config
 from webhelpers.rails.tags import content_tag, tag_options
 
     extra_options = tag_options(**href_options)
     def handle_match(matchobj):
         all = matchobj.group()
-        a, b, c, d = matchobj.group(1,2,3,4)
+        a, b, c, d = matchobj.group(1, 2, 3, 4)
         if re.match(r'<a\s', a, re.I):
             return all
         text = b + c
     return re.sub(AUTO_LINK_RE, handle_match, text)
 
 def auto_link_email_addresses(text):
-    def fix_email(match):
-        text = matchobj.group()
-        return '<a href="mailto:%s>%s</a>' % (text, text)
-    return re.sub(r'([\w\.!#\$%\-+.]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)+)', r'<a href="mailto:\1">\1</a>', text)
+    return re.sub(r'([\w\.!#\$%\-+.]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)+)',
+                  r'<a href="mailto:\1">\1</a>', text)
 
 def strip_links(text):
     """
     texer = textile.Textiler(text)
     return texer.process(sanitize=sanitize)
 
-def markdown(text):
+def markdown(text, **kwargs):
     """Format the text with MarkDown formatting
     
     This function uses the `Python MarkDown library <http://www.freewisdom.org/projects/python-markdown/>`_
     which is included with WebHelpers.
     
     """
-    return markdown.markdown(text)
+    return _markdown.markdown(text, **kwargs)
 
 __all__ = ['cycle', 'reset_cycle', 'counter', 'reset_counter', 'truncate', 'highlight', 'excerpt',
            'word_wrap', 'simple_format', 'auto_link', 'strip_links', 'textilize', 'markdown']
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.