summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgbrandl <devnull@localhost>2009-09-14 17:47:57 +0200
committergbrandl <devnull@localhost>2009-09-14 17:47:57 +0200
commit19618cef9e928309ba86fd11175c945d4ade63f8 (patch)
tree023d68fd74821b5bb399af75a096217364517216
parentb61ff6e9b9245251b8ee9139847d6ce6c9ae8190 (diff)
downloadpygments-19618cef9e928309ba86fd11175c945d4ade63f8.tar.gz
Improved the BBCode lexer (#435).
* don't emit errors on punctuation in normal text * highlight tag names as Keyword * highlight multiple attributes correctly
-rw-r--r--CHANGES3
-rw-r--r--pygments/lexers/text.py23
2 files changed, 20 insertions, 6 deletions
diff --git a/CHANGES b/CHANGES
index 8b40145a..388e4446 100644
--- a/CHANGES
+++ b/CHANGES
@@ -7,8 +7,11 @@ Version 1.2
-----------
(codename to be selected, release date unknown)
+- Improved the BBCode lexer (#435).
+
- Added support for new Jinja2 keywords.
+
Version 1.1
-----------
(codename Brillouin, released Sep 11, 2009)
diff --git a/pygments/lexers/text.py b/pygments/lexers/text.py
index 24b9f6f4..efc346d5 100644
--- a/pygments/lexers/text.py
+++ b/pygments/lexers/text.py
@@ -356,12 +356,23 @@ class BBCodeLexer(RegexLexer):
mimetypes = ['text/x-bbcode']
tokens = {
- 'root' : [
- (r'[\s\w]+', Text),
- (r'(\[)(/?[^\]\n\r=]+)(\])',
- bygroups(Keyword, Keyword.Pseudo, Keyword)),
- (r'(\[)([^\]\n\r=]+)(=)([^\]\n\r]+)(\])',
- bygroups(Keyword, Keyword.Pseudo, Operator, String, Keyword)),
+ 'root': [
+ (r'[^[]+', Text),
+ # tag/end tag begin
+ (r'\[/?\w+', Keyword, 'tag'),
+ # stray bracket
+ (r'\[', Text),
+ ],
+ 'tag': [
+ (r'\s+', Text),
+ # attribute with value
+ (r'(\w+)(=)("?[^\s"\]]+"?)',
+ bygroups(Name.Attribute, Operator, String)),
+ # tag argument (a la [color=green])
+ (r'(=)("?[^\s"\]]+"?)',
+ bygroups(Operator, String)),
+ # tag end
+ (r'\]', Keyword, '#pop'),
],
}