summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Balmos <andrew@balmos.org>2014-10-09 11:11:34 -0400
committerAndrew Balmos <andrew@balmos.org>2014-10-09 11:11:34 -0400
commitececf9767b5cc2a5ae633f05e0ad8e09e1d3ace2 (patch)
treef0d07801609d0d1e8d5bdb8c8796e3cb461162b2
parent87781e3aa6748b035a822a3a8fdf2cedd53d478b (diff)
downloadpygments-ececf9767b5cc2a5ae633f05e0ad8e09e1d3ace2.tar.gz
Also checks mediatype suffix for lexer in HttpLexer
The HttpLexer will highlight the body if the Content-Type header is set to a mediatype that pygments understands. However, some mediatypes have a custom subtype but a standard and known suffix. Therefore, pygments should highlight body by the exact media type first and then by the suffix if there was no match. For example: application/vnd.custom+json currently does not result in the body being highlighted even though pygments is capable application/json
-rw-r--r--pygments/lexers/textfmts.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/pygments/lexers/textfmts.py b/pygments/lexers/textfmts.py
index e3700e9f..04222562 100644
--- a/pygments/lexers/textfmts.py
+++ b/pygments/lexers/textfmts.py
@@ -154,6 +154,16 @@ class HttpLexer(RegexLexer):
for idx, token, value in lexer.get_tokens_unprocessed(content):
yield offset + idx, token, value
return
+ # Check for with just the suffix
+ content_type = re.sub(r'^(.*)/.*\+(.*)$', r'\1/\2', content_type)
+ try:
+ lexer = get_lexer_for_mimetype(content_type)
+ except ClassNotFound:
+ pass
+ else:
+ for idx, token, value in lexer.get_tokens_unprocessed(content):
+ yield offset + idx, token, value
+ return
yield offset, Text, content
tokens = {