summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Hatch <tim@timhatch.com>2014-10-08 18:55:35 -0700
committerTim Hatch <tim@timhatch.com>2014-10-08 18:55:35 -0700
commit87781e3aa6748b035a822a3a8fdf2cedd53d478b (patch)
tree85da94f2627df7405c2a989f4e430ddda3bcf9db
parent6f82393fe38d73ffc2ef61b16722c603e41b6ec2 (diff)
downloadpygments-87781e3aa6748b035a822a3a8fdf2cedd53d478b.tar.gz
Add JSON-LD Lexer.
Adapted from PR 289.
-rw-r--r--pygments/lexers/_mapping.py1
-rw-r--r--pygments/lexers/data.py25
-rw-r--r--tests/examplefiles/example.jsonld27
3 files changed, 51 insertions, 2 deletions
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py
index 8ee280ca..6d7c94df 100644
--- a/pygments/lexers/_mapping.py
+++ b/pygments/lexers/_mapping.py
@@ -176,6 +176,7 @@ LEXERS = {
'JavascriptLexer': ('pygments.lexers.javascript', 'JavaScript', ('js', 'javascript'), ('*.js',), ('application/javascript', 'application/x-javascript', 'text/x-javascript', 'text/javascript')),
'JavascriptPhpLexer': ('pygments.lexers.templates', 'JavaScript+PHP', ('js+php', 'javascript+php'), (), ('application/x-javascript+php', 'text/x-javascript+php', 'text/javascript+php')),
'JavascriptSmartyLexer': ('pygments.lexers.templates', 'JavaScript+Smarty', ('js+smarty', 'javascript+smarty'), (), ('application/x-javascript+smarty', 'text/x-javascript+smarty', 'text/javascript+smarty')),
+ 'JsonLdLexer': ('pygments.lexers.data', 'JSON-LD', ('json-ld',), ('*.jsonld',), ('application/json-ld',)),
'JsonLexer': ('pygments.lexers.data', 'JSON', ('json',), ('*.json',), ('application/json',)),
'JspLexer': ('pygments.lexers.templates', 'Java Server Page', ('jsp',), ('*.jsp',), ('application/x-jsp',)),
'JuliaConsoleLexer': ('pygments.lexers.julia', 'Julia console', ('jlcon',), (), ()),
diff --git a/pygments/lexers/data.py b/pygments/lexers/data.py
index 6b7cc107..6ea331f6 100644
--- a/pygments/lexers/data.py
+++ b/pygments/lexers/data.py
@@ -12,11 +12,11 @@
import re
from pygments.lexer import RegexLexer, ExtendedRegexLexer, LexerContext, \
- include, bygroups
+ include, bygroups, inherit
from pygments.token import Text, Comment, Keyword, Name, String, Number, \
Punctuation, Literal
-__all__ = ['YamlLexer', 'JsonLexer']
+__all__ = ['YamlLexer', 'JsonLexer', 'JsonLdLexer']
class YamlLexerContext(LexerContext):
@@ -507,3 +507,24 @@ class JsonLexer(RegexLexer):
include('value'),
],
}
+
+class JsonLdLexer(JsonLexer):
+ """
+ For `JSON-LD <http://json-ld.org/>`_ linked data.
+
+ .. versionadded:: 2.0
+ """
+
+ name = 'JSON-LD'
+ aliases = ['jsonld', 'json-ld']
+ filenames = ['*.jsonld']
+ mimetypes = ['application/ld+json']
+
+ tokens = {
+ 'objectvalue': [
+ (r'"@(context|id|value|language|type|container|list|set|'
+ r'reverse|index|base|vocab|graph)"', Name.Decorator,
+ 'objectattribute'),
+ inherit,
+ ],
+ }
diff --git a/tests/examplefiles/example.jsonld b/tests/examplefiles/example.jsonld
new file mode 100644
index 00000000..48787d75
--- /dev/null
+++ b/tests/examplefiles/example.jsonld
@@ -0,0 +1,27 @@
+{
+ "@context": {
+ "schema": "http://schema.org/",
+ "name": "schema:name",
+ "body": "schema:articleBody",
+ "words": "schema:wordCount",
+ "post": {
+ "@id": "schema:blogPost",
+ "@container": "@index"
+ }
+ },
+ "@id": "http://example.com/",
+ "@type": "schema:Blog",
+ "name": "World Financial News",
+ "post": {
+ "en": {
+ "@id": "http://example.com/posts/1/en",
+ "body": "World commodities were up today with heavy trading of crude oil...",
+ "words": 1539
+ },
+ "de": {
+ "@id": "http://example.com/posts/1/de",
+ "body": "Die Werte an Warenbörsen stiegen im Sog eines starken Handels von Rohöl...",
+ "words": 1204
+ }
+ }
+}