Commits

Anonymous committed 268054b

Factor out legacy highlighter code.

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

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, [

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.
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.