Commits

slug...@gmail.com  committed 268054b

Factor out legacy highlighter code.

  • Participants
  • Parent commits 155effd

Comments (0)

Files changed (3)

 
 Routes_
 
-    Version >= 1.7 but < 2.0 must be installed and running in the current
+    Version >= 1.7 must be installed and running in the current
     web framework for:
 
     - webhelpers.html.tags (required only for ``javascript_link()``,
 
     Currently Pylons_, TurboGears_, and Aquarium_ support Routes.
 
-    A future version of WebHelpers will be compatible with Routes 2, which is
-    still in development.
-
 Pylons_
 
     The helpers in ``webhelpers.pylonslib`` depend on Pylons context variables

File tests/test_tools.py

         eq_(literal(u'The <red> c<strong class="highlight">at</strong>.'),
             highlight(literal("The <red> cat."), "at"))
 
+    def test_highlight_legacy_highlighter(self):
+        eq_("This is a <b>beautiful</b> morning, but also a <b>beautiful</b> day",
+                         highlight("This is a beautiful morning, but also a beautiful day",
+                                   "beautiful", r'<b>\1</b>'))
 
 if __name__ == '__main__':
     suite = map(unittest.makeSuite, [

File webhelpers/html/tools.py

     else:
         flags = re.IGNORECASE
     if highlighter:
-        warnings.warn("the ``highlighter`` argument is deprecated",
-            DeprecationWarning)
-        pat = "(%s)" % re.escape(phrase)
-        rx = re.compile(pat, flags)
-        return lit_sub(rx, highlighter, text)
+        return _legacy_highlight(text, phrase, highlighter, flags)
     if isinstance(phrase, basestring):
         pat = re.escape(phrase)
         rx = re.compile(pat, flags)
     return lit_sub(rx, repl, text)
 
 
+def _legacy_highlight(text, phrase, highlighter, flags):
+    """WebHelpers 0.6 style highlight with deprecated ``highlighter arg."""
+    warnings.warn("the ``highlighter`` argument is deprecated",
+        DeprecationWarning)
+    pat = "(%s)" % re.escape(phrase)
+    rx = re.compile(pat, flags)
+    highlighter = literal(highlighter)
+    return lit_sub(rx, highlighter, text)
+    
+
 def auto_link(text, link="all", **href_options):
     """
     Turn all urls and email addresses into clickable links.