summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2011-06-18 11:32:12 +0200
committerGeorg Brandl <georg@python.org>2011-06-18 11:32:12 +0200
commitf4f58dba7a5f75e0eddc8a2e9b2c2376fd1fc05e (patch)
treeff9fe84dc861dffaffa9cc44bd81f09f800f4d0e
parent645c0dc544a11ea2a0583449edbd617ee23035f0 (diff)
downloadpygments-f4f58dba7a5f75e0eddc8a2e9b2c2376fd1fc05e.tar.gz
Several fixes to the reStructuredText lexer (#636):
* recognize end of inline code properly and don't view \ as escape in there * fix markup for hyperlink targets
-rw-r--r--CHANGES2
-rw-r--r--pygments/lexers/text.py18
2 files changed, 14 insertions, 6 deletions
diff --git a/CHANGES b/CHANGES
index 540a837a..0b09e2ac 100644
--- a/CHANGES
+++ b/CHANGES
@@ -20,6 +20,8 @@ Version 1.5
- Enhancements to the Squid conf lexer (#664).
+- Several fixes to the reStructuredText lexer (#636).
+
- Fix Lua "class" highlighting: it does not have classes (#665).
- Fix degenerate regex in Scala lexer (#671).
diff --git a/pygments/lexers/text.py b/pygments/lexers/text.py
index 82f5f5b7..e481bb62 100644
--- a/pygments/lexers/text.py
+++ b/pygments/lexers/text.py
@@ -653,6 +653,13 @@ class RstLexer(RegexLexer):
for item in do_insertions(ins, lexer.get_tokens_unprocessed(code)):
yield item
+ # from docutils.parsers.rst.states
+ closers = u'\'")]}>\u2019\u201d\xbb!?'
+ unicode_delimiters = u'\u2010\u2011\u2012\u2013\u2014\u00a0'
+ end_string_suffix = (r'((?=$)|(?=[-/:.,; \n\x00%s%s]))'
+ % (re.escape(unicode_delimiters),
+ re.escape(closers)))
+
tokens = {
'root': [
# Heading with overline
@@ -689,9 +696,9 @@ class RstLexer(RegexLexer):
bygroups(Punctuation, Text, Operator.Word, Punctuation, Text,
using(this, state='inline'))),
# A reference target
- (r'^( *\.\.)(\s*)([\w\t ]+:)(.*?)$',
+ (r'^( *\.\.)(\s*)(_(?:[^:\\]|\\.)+:)(.*?)$',
bygroups(Punctuation, Text, Name.Tag, using(this, state='inline'))),
- # A footnote target
+ # A footnote/citation target
(r'^( *\.\.)(\s*)(\[.+\])(.*?)$',
bygroups(Punctuation, Text, Name.Tag, using(this, state='inline'))),
# A substitution def
@@ -730,10 +737,9 @@ class RstLexer(RegexLexer):
(r'.', Text),
],
'literal': [
- (r'[^`\\]+', String),
- (r'\\.', String),
- (r'``', String, '#pop'),
- (r'[`\\]', String),
+ (r'[^`]+', String),
+ (r'``' + end_string_suffix, String, '#pop'),
+ (r'`', String),
]
}