GraphQL: Added support for multi-line strings and descriptions (#2406)
This commit is contained in:
parent
ed715158c7
commit
9e64c62e3c
File diff suppressed because one or more lines are too long
|
@ -397,6 +397,7 @@
|
|||
},
|
||||
"graphql": {
|
||||
"title": "GraphQL",
|
||||
"optional": ["markdown"],
|
||||
"owner": "Golmote"
|
||||
},
|
||||
"groovy": {
|
||||
|
|
|
@ -1,7 +1,19 @@
|
|||
Prism.languages.graphql = {
|
||||
'comment': /#.*/,
|
||||
'description': {
|
||||
pattern: /(?:"""(?:[^"]|(?!""")")*"""|"(?:\\.|[^\\"\r\n])*")(?=\s*[a-z_])/i,
|
||||
greedy: true,
|
||||
alias: 'string',
|
||||
inside: {
|
||||
'language-markdown': {
|
||||
pattern: /(^"(?:"")?)(?!\1)[\s\S]+(?=\1$)/,
|
||||
lookbehind: true,
|
||||
inside: Prism.languages.markdown
|
||||
}
|
||||
}
|
||||
},
|
||||
'string': {
|
||||
pattern: /"(?:\\.|[^\\"\r\n])*"/,
|
||||
pattern: /"""(?:[^"]|(?!""")")*"""|"(?:\\.|[^\\"\r\n])*"/,
|
||||
greedy: true
|
||||
},
|
||||
'number': /(?:\B-|\b)\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i,
|
||||
|
|
|
@ -1 +1 @@
|
|||
Prism.languages.graphql={comment:/#.*/,string:{pattern:/"(?:\\.|[^\\"\r\n])*"/,greedy:!0},number:/(?:\B-|\b)\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i,boolean:/\b(?:true|false)\b/,variable:/\$[a-z_]\w*/i,directive:{pattern:/@[a-z_]\w*/i,alias:"function"},"attr-name":{pattern:/[a-z_]\w*(?=\s*(?:\((?:[^()"]|"(?:\\.|[^\\"\r\n])*")*\))?:)/i,greedy:!0},"class-name":{pattern:/(\b(?:enum|implements|interface|on|scalar|type|union)\s+)[a-zA-Z_]\w*/,lookbehind:!0},fragment:{pattern:/(\bfragment\s+|\.{3}\s*(?!on\b))[a-zA-Z_]\w*/,lookbehind:!0,alias:"function"},keyword:/\b(?:enum|fragment|implements|input|interface|mutation|on|query|scalar|schema|type|union)\b/,operator:/[!=|]|\.{3}/,punctuation:/[!(){}\[\]:=,]/,constant:/\b(?!ID\b)[A-Z][A-Z_\d]*\b/};
|
||||
Prism.languages.graphql={comment:/#.*/,description:{pattern:/(?:"""(?:[^"]|(?!""")")*"""|"(?:\\.|[^\\"\r\n])*")(?=\s*[a-z_])/i,greedy:!0,alias:"string",inside:{"language-markdown":{pattern:/(^"(?:"")?)(?!\1)[\s\S]+(?=\1$)/,lookbehind:!0,inside:Prism.languages.markdown}}},string:{pattern:/"""(?:[^"]|(?!""")")*"""|"(?:\\.|[^\\"\r\n])*"/,greedy:!0},number:/(?:\B-|\b)\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i,boolean:/\b(?:true|false)\b/,variable:/\$[a-z_]\w*/i,directive:{pattern:/@[a-z_]\w*/i,alias:"function"},"attr-name":{pattern:/[a-z_]\w*(?=\s*(?:\((?:[^()"]|"(?:\\.|[^\\"\r\n])*")*\))?:)/i,greedy:!0},"class-name":{pattern:/(\b(?:enum|implements|interface|on|scalar|type|union)\s+)[a-zA-Z_]\w*/,lookbehind:!0},fragment:{pattern:/(\bfragment\s+|\.{3}\s*(?!on\b))[a-zA-Z_]\w*/,lookbehind:!0,alias:"function"},keyword:/\b(?:enum|fragment|implements|input|interface|mutation|on|query|scalar|schema|type|union)\b/,operator:/[!=|]|\.{3}/,punctuation:/[!(){}\[\]:=,]/,constant:/\b(?!ID\b)[A-Z][A-Z_\d]*\b/};
|
|
@ -3,7 +3,10 @@
|
|||
|
||||
<h2>Strings</h2>
|
||||
<pre><code>""
|
||||
"foo \"bar\" baz"</code></pre>
|
||||
"foo \"bar\" baz"
|
||||
""" "Multi-line" strings
|
||||
are supported."""
|
||||
</code></pre>
|
||||
|
||||
<h2>Numbers</h2>
|
||||
<pre><code>0
|
||||
|
@ -28,4 +31,32 @@ fragment friendFields on User {
|
|||
id
|
||||
name
|
||||
profilePic(size: 50)
|
||||
}</code></pre>
|
||||
}</code></pre>
|
||||
|
||||
<p>Markdown inside of descriptions require markdown to be loaded.
|
||||
On this page, checking Markdown <strong>before</strong> checking GraphQL should
|
||||
make the example below work properly.</p>
|
||||
|
||||
<h2>Descriptions</h2>
|
||||
<pre><code>"""
|
||||
This is a multiline description
|
||||
# Heading
|
||||
[Prism](http://www.prismjs.com)
|
||||
|
||||
It can contain **Markdown
|
||||
on multiple lines**
|
||||
"""
|
||||
type Example {
|
||||
id: ID!
|
||||
}
|
||||
|
||||
type Sample {
|
||||
"""
|
||||
Simple multiline description
|
||||
"""
|
||||
name(
|
||||
"This is a single line description"
|
||||
first: Int
|
||||
): String
|
||||
}
|
||||
</code></pre>
|
|
@ -0,0 +1,34 @@
|
|||
"Single-line description"
|
||||
type Foo {}
|
||||
"""
|
||||
Multiline description
|
||||
"""
|
||||
type Bar {}
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["description", [
|
||||
"\"",
|
||||
["language-markdown", "Single-line description"],
|
||||
"\""
|
||||
]],
|
||||
["keyword", "type"],
|
||||
["class-name", "Foo"],
|
||||
["punctuation", "{"],
|
||||
["punctuation", "}"],
|
||||
|
||||
["description", [
|
||||
"\"\"\"",
|
||||
["language-markdown", "\r\nMultiline description\r\n"],
|
||||
"\"\"\""
|
||||
]],
|
||||
["keyword", "type"],
|
||||
["class-name", "Bar"],
|
||||
["punctuation", "{"],
|
||||
["punctuation", "}"]
|
||||
]
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
Checks for descriptions.
|
|
@ -1,13 +1,16 @@
|
|||
""
|
||||
"foo bar"
|
||||
"foo\"bar\\baz"
|
||||
"""multi-line
|
||||
string"""
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["string", "\"\""],
|
||||
["string", "\"foo bar\""],
|
||||
["string", "\"foo\\\"bar\\\\baz\""]
|
||||
["string", "\"foo\\\"bar\\\\baz\""],
|
||||
["string", "\"\"\"multi-line\r\nstring\"\"\""]
|
||||
]
|
||||
|
||||
----------------------------------------------------
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
"""
|
||||
Complex multiline description
|
||||
# Title
|
||||
"""
|
||||
type Baz {}
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["description", [
|
||||
"\"\"\"",
|
||||
["language-markdown", [
|
||||
"\r\nComplex multiline description\r\n",
|
||||
["title", [["punctuation", "#"], " Title"]]
|
||||
]],
|
||||
"\"\"\""
|
||||
]],
|
||||
["keyword", "type"],
|
||||
["class-name", "Baz"],
|
||||
["punctuation", "{"],
|
||||
["punctuation", "}"]
|
||||
]
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
Checks for descriptions.
|
Loading…
Reference in New Issue