diff options
author | thatch <devnull@localhost> | 2008-10-08 20:08:20 -0700 |
---|---|---|
committer | thatch <devnull@localhost> | 2008-10-08 20:08:20 -0700 |
commit | 3b2574fd7b64a01a7df795a7b0bbc8a1ffa298ab (patch) | |
tree | 98a3b4c77e164ae2b08d615a73bf68a9d2cdf4d6 | |
parent | e4eb439164fd41ae18aff84b552c58f081d9be30 (diff) | |
download | pygments-3b2574fd7b64a01a7df795a7b0bbc8a1ffa298ab.tar.gz |
Fix #368 by requiring word boundaries for codetag filter.
-rw-r--r-- | pygments/filters/__init__.py | 2 | ||||
-rw-r--r-- | tests/test_basic_api.py | 16 |
2 files changed, 17 insertions, 1 deletions
diff --git a/pygments/filters/__init__.py b/pygments/filters/__init__.py index efe8a4bd..971e2630 100644 --- a/pygments/filters/__init__.py +++ b/pygments/filters/__init__.py @@ -85,7 +85,7 @@ class CodeTagFilter(Filter): Filter.__init__(self, **options) tags = get_list_opt(options, 'codetags', ['XXX', 'TODO', 'BUG', 'NOTE']) - self.tag_re = re.compile(r'(%s)' % '|'.join([ + self.tag_re = re.compile(r'\b(%s)\b' % '|'.join([ re.escape(tag) for tag in tags if tag ])) diff --git a/tests/test_basic_api.py b/tests/test_basic_api.py index 1168c7ad..4126279c 100644 --- a/tests/test_basic_api.py +++ b/tests/test_basic_api.py @@ -121,6 +121,22 @@ class FiltersTest(unittest.TestCase): lxtext = ''.join([t[1] for t in list(lx.get_tokens(text))]) self.assert_('Def' in lxtext and 'Class' in lxtext) + def test_codetag(self): + lx = lexers.PythonLexer() + lx.add_filter('codetagify') + text = u'# BUG: text' + tokens = list(lx.get_tokens(text)) + self.assertEquals('# ', tokens[0][1]) + self.assertEquals('BUG', tokens[1][1]) + + def test_codetag_boundary(self): + # http://dev.pocoo.org/projects/pygments/ticket/368 + lx = lexers.PythonLexer() + lx.add_filter('codetagify') + text = u'# DEBUG: text' + tokens = list(lx.get_tokens(text)) + self.assertEquals('# DEBUG: text', tokens[0][1]) + class FormattersTest(unittest.TestCase): |