Skip to content

Commit 9e64c62

Browse files
authored
GraphQL: Added support for multi-line strings and descriptions (#2406)
1 parent ed71515 commit 9e64c62

File tree

8 files changed

+113
-6
lines changed

8 files changed

+113
-6
lines changed

Diff for: components.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: components.json

+1
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@
397397
},
398398
"graphql": {
399399
"title": "GraphQL",
400+
"optional": ["markdown"],
400401
"owner": "Golmote"
401402
},
402403
"groovy": {

Diff for: components/prism-graphql.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
Prism.languages.graphql = {
22
'comment': /#.*/,
3+
'description': {
4+
pattern: /(?:"""(?:[^"]|(?!""")")*"""|"(?:\\.|[^\\"\r\n])*")(?=\s*[a-z_])/i,
5+
greedy: true,
6+
alias: 'string',
7+
inside: {
8+
'language-markdown': {
9+
pattern: /(^"(?:"")?)(?!\1)[\s\S]+(?=\1$)/,
10+
lookbehind: true,
11+
inside: Prism.languages.markdown
12+
}
13+
}
14+
},
315
'string': {
4-
pattern: /"(?:\\.|[^\\"\r\n])*"/,
16+
pattern: /"""(?:[^"]|(?!""")")*"""|"(?:\\.|[^\\"\r\n])*"/,
517
greedy: true
618
},
719
'number': /(?:\B-|\b)\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i,

Diff for: components/prism-graphql.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: examples/prism-graphql.html

+33-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ <h2>Comments</h2>
33

44
<h2>Strings</h2>
55
<pre><code>""
6-
"foo \"bar\" baz"</code></pre>
6+
"foo \"bar\" baz"
7+
""" "Multi-line" strings
8+
are supported."""
9+
</code></pre>
710

811
<h2>Numbers</h2>
912
<pre><code>0
@@ -28,4 +31,32 @@ <h2>Keywords</h2>
2831
id
2932
name
3033
profilePic(size: 50)
31-
}</code></pre>
34+
}</code></pre>
35+
36+
<p>Markdown inside of descriptions require markdown to be loaded.
37+
On this page, checking Markdown <strong>before</strong> checking GraphQL should
38+
make the example below work properly.</p>
39+
40+
<h2>Descriptions</h2>
41+
<pre><code>"""
42+
This is a multiline description
43+
# Heading
44+
[Prism](http://www.prismjs.com)
45+
46+
It can contain **Markdown
47+
on multiple lines**
48+
"""
49+
type Example {
50+
id: ID!
51+
}
52+
53+
type Sample {
54+
"""
55+
Simple multiline description
56+
"""
57+
name(
58+
"This is a single line description"
59+
first: Int
60+
): String
61+
}
62+
</code></pre>

Diff for: tests/languages/graphql/description_feature.test

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"Single-line description"
2+
type Foo {}
3+
"""
4+
Multiline description
5+
"""
6+
type Bar {}
7+
8+
----------------------------------------------------
9+
10+
[
11+
["description", [
12+
"\"",
13+
["language-markdown", "Single-line description"],
14+
"\""
15+
]],
16+
["keyword", "type"],
17+
["class-name", "Foo"],
18+
["punctuation", "{"],
19+
["punctuation", "}"],
20+
21+
["description", [
22+
"\"\"\"",
23+
["language-markdown", "\r\nMultiline description\r\n"],
24+
"\"\"\""
25+
]],
26+
["keyword", "type"],
27+
["class-name", "Bar"],
28+
["punctuation", "{"],
29+
["punctuation", "}"]
30+
]
31+
32+
----------------------------------------------------
33+
34+
Checks for descriptions.

Diff for: tests/languages/graphql/string_feature.test

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
""
22
"foo bar"
33
"foo\"bar\\baz"
4+
"""multi-line
5+
string"""
46

57
----------------------------------------------------
68

79
[
810
["string", "\"\""],
911
["string", "\"foo bar\""],
10-
["string", "\"foo\\\"bar\\\\baz\""]
12+
["string", "\"foo\\\"bar\\\\baz\""],
13+
["string", "\"\"\"multi-line\r\nstring\"\"\""]
1114
]
1215

1316
----------------------------------------------------
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
Complex multiline description
3+
# Title
4+
"""
5+
type Baz {}
6+
7+
----------------------------------------------------
8+
9+
[
10+
["description", [
11+
"\"\"\"",
12+
["language-markdown", [
13+
"\r\nComplex multiline description\r\n",
14+
["title", [["punctuation", "#"], " Title"]]
15+
]],
16+
"\"\"\""
17+
]],
18+
["keyword", "type"],
19+
["class-name", "Baz"],
20+
["punctuation", "{"],
21+
["punctuation", "}"]
22+
]
23+
24+
----------------------------------------------------
25+
26+
Checks for descriptions.

0 commit comments

Comments
 (0)