Skip to content

Commit

Permalink
Merge pull request #971 from Golmote/prism-graphql
Browse files Browse the repository at this point in the history
Add support for GraphQL
  • Loading branch information
Golmote authored Jun 16, 2016
2 parents a263362 + bfb559b commit e018087
Show file tree
Hide file tree
Showing 14 changed files with 206 additions and 2 deletions.
4 changes: 4 additions & 0 deletions components.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ var components = {
"require": "clike",
"owner": "arnehormann"
},
"graphql": {
"title": "GraphQL",
"owner": "Golmote"
},
"groovy": {
"title": "Groovy",
"require": "clike",
Expand Down
24 changes: 24 additions & 0 deletions components/prism-graphql.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Prism.languages.graphql = {
'comment': /#.*/,
'string': {
pattern: /"(?:\\.|[^\\"])*"/,
greedy: true
},
'number': /(?:\B-|\b)\d+(?:\.\d+)?(?:[eE][+-]?\d+)?\b/,
'boolean': /\b(?:true|false)\b/,
'variable': /\$[a-z_]\w*/i,
'directive': {
pattern: /@[a-z_]\w*/i,
alias: 'function'
},
'attr-name': /[a-z_]\w*(?=\s*:)/i,
'keyword': [
{
pattern: /(fragment\s+(?!on)[a-z_]\w*\s+|\.\.\.\s*)on\b/,
lookbehind: true
},
/\b(?:query|fragment|mutation)\b/
],
'operator': /!|=|\.{3}/,
'punctuation': /[!(){}\[\]:=,]/
};
1 change: 1 addition & 0 deletions components/prism-graphql.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions examples/prism-graphql.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<h1>GraphQL</h1>
<p>To use this language, use the class "language-graphql".</p>

<h2>Comments</h2>
<pre><code># This is a comment</code></pre>

<h2>Strings</h2>
<pre><code>""
"foo \"bar\" baz"</code></pre>

<h2>Numbers</h2>
<pre><code>0
42
3.14159
-9e-5
0.9E+7</code></pre>

<h2>Keywords</h2>
<pre><code>query withFragments {
user(id: 4) {
friends(first: 10) {
...friendFields
}
mutualFriends(first: 10) {
...friendFields
}
}
}

fragment friendFields on User {
id
name
profilePic(size: 50)
}</code></pre>
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if (typeof self === 'undefined' || !self.Prism || !self.document) {
}

// The languages map is built automatically with gulp
var Languages = /*languages_placeholder[*/{"html":"HTML","xml":"XML","svg":"SVG","mathml":"MathML","css":"CSS","clike":"C-like","javascript":"JavaScript","abap":"ABAP","actionscript":"ActionScript","apacheconf":"Apache Configuration","apl":"APL","applescript":"AppleScript","asciidoc":"AsciiDoc","aspnet":"ASP.NET (C#)","autoit":"AutoIt","autohotkey":"AutoHotkey","basic":"BASIC","csharp":"C#","cpp":"C++","coffeescript":"CoffeeScript","css-extras":"CSS Extras","fsharp":"F#","glsl":"GLSL","http":"HTTP","inform7":"Inform 7","json":"JSON","latex":"LaTeX","lolcode":"LOLCODE","matlab":"MATLAB","mel":"MEL","nasm":"NASM","nginx":"nginx","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","parigp":"PARI/GP","php":"PHP","php-extras":"PHP Extras","powershell":"PowerShell","protobuf":"Protocol Buffers","jsx":"React JSX","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","typescript":"TypeScript","vhdl":"VHDL","vim":"vim","wiki":"Wiki markup","yaml":"YAML"}/*]*/;
var Languages = /*languages_placeholder[*/{"html":"HTML","xml":"XML","svg":"SVG","mathml":"MathML","css":"CSS","clike":"C-like","javascript":"JavaScript","abap":"ABAP","actionscript":"ActionScript","apacheconf":"Apache Configuration","apl":"APL","applescript":"AppleScript","asciidoc":"AsciiDoc","aspnet":"ASP.NET (C#)","autoit":"AutoIt","autohotkey":"AutoHotkey","basic":"BASIC","csharp":"C#","cpp":"C++","coffeescript":"CoffeeScript","css-extras":"CSS Extras","fsharp":"F#","glsl":"GLSL","graphql":"GraphQL","http":"HTTP","inform7":"Inform 7","json":"JSON","latex":"LaTeX","lolcode":"LOLCODE","matlab":"MATLAB","mel":"MEL","nasm":"NASM","nginx":"nginx","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","parigp":"PARI/GP","php":"PHP","php-extras":"PHP Extras","powershell":"PowerShell","protobuf":"Protocol Buffers","jsx":"React JSX","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","typescript":"TypeScript","vhdl":"VHDL","vim":"vim","wiki":"Wiki markup","yaml":"YAML"}/*]*/;
Prism.hooks.add('before-highlight', function(env) {
var pre = env.element.parentNode;
if (!pre || !/pre/i.test(pre.nodeName)) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions tests/languages/graphql/attr-name_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
zuck: user(id: 4) {
name
}
}

----------------------------------------------------

[
["punctuation", "{"],
["attr-name", "zuck"],
["punctuation", ":"],
" user",
["punctuation", "("],
["attr-name", "id"],
["punctuation", ":"],
["number", "4"],
["punctuation", ")"],
["punctuation", "{"],
"\r\n\t\tname\r\n\t",
["punctuation", "}"],
["punctuation", "}"]
]

----------------------------------------------------

Checks for aliases, parameter names, etc.
13 changes: 13 additions & 0 deletions tests/languages/graphql/boolean_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
true
false

----------------------------------------------------

[
["boolean", "true"],
["boolean", "false"]
]

----------------------------------------------------

Checks for booleans.
13 changes: 13 additions & 0 deletions tests/languages/graphql/comment_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#
# foobar

----------------------------------------------------

[
["comment", "#"],
["comment", "# foobar"]
]

----------------------------------------------------

Checks for comments.
13 changes: 13 additions & 0 deletions tests/languages/graphql/directive_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@skip
@include

----------------------------------------------------

[
["directive", "@skip"],
["directive", "@include"]
]

----------------------------------------------------

Checks for directives
24 changes: 24 additions & 0 deletions tests/languages/graphql/keyword_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
query
fragment
mutation
fragment foo on Bar
... on Foo

----------------------------------------------------

[
["keyword", "query"],
["keyword", "fragment"],
["keyword", "mutation"],
["keyword", "fragment"],
" foo ",
["keyword", "on"],
" Bar\r\n",
["operator", "..."],
["keyword", "on"],
" Foo"
]

----------------------------------------------------

Checks for keywords.
23 changes: 23 additions & 0 deletions tests/languages/graphql/number_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
0
42
-5
3.14159
5e4
6E-78
0.3e+1

----------------------------------------------------

[
["number", "0"],
["number", "42"],
["number", "-5"],
["number", "3.14159"],
["number", "5e4"],
["number", "6E-78"],
["number", "0.3e+1"]
]

----------------------------------------------------

Checks for numbers.
15 changes: 15 additions & 0 deletions tests/languages/graphql/string_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
""
"foo bar"
"foo\"bar\\baz"

----------------------------------------------------

[
["string", "\"\""],
["string", "\"foo bar\""],
["string", "\"foo\\\"bar\\\\baz\""]
]

----------------------------------------------------

Checks for strings.
13 changes: 13 additions & 0 deletions tests/languages/graphql/variable_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
$foo
$Foo_bar42

----------------------------------------------------

[
["variable", "$foo"],
["variable", "$Foo_bar42"]
]

----------------------------------------------------

Checks for variables.

0 comments on commit e018087

Please sign in to comment.