Skip to content

Commit

Permalink
feat: adding highlight support for graphql (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
erunion authored Sep 17, 2021
1 parent fd2b221 commit 8ffcb52
Show file tree
Hide file tree
Showing 10 changed files with 197 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const ele = syntaxHighlighter('console.log("Hello, world!");', 'js', { ...opts,
| Docker | `dockerfile` |
| Erlang | `erl`, `erlang` |
| Go | `go` |
| GraphQL | `gql`, `graphql` |
| Groovy | `gradle`, `groovy` |
| Handlebars | `handlebars`, `hbs` |
| HTML/XML | `html`, `xhtml`, `xml` |
Expand Down
9 changes: 9 additions & 0 deletions __tests__/__fixtures__/graphql/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
language: 'GraphQL',
mode: {
primary: 'graphql',
aliases: {
gql: 'GraphQL',
},
},
};
19 changes: 19 additions & 0 deletions __tests__/__fixtures__/graphql/sample.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
person(id: 4) {
name
}
allFilms {
totalCount
films {
releaseDate
planetConnection {
planets {
id
surfaceWater
climates
terrains
}
}
}
}
}
23 changes: 23 additions & 0 deletions __tests__/__snapshots__/codeMirror.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,29 @@ exports[`Supported languages Go should syntax highlight an example 1`] = `
</div>"
`;
exports[`Supported languages GraphQL should syntax highlight an example 1`] = `
"<div class=\\"cm-s-neo\\"><span class=\\"cm-punctuation\\">{</span>
<span class=\\"cm-ws\\"> </span><span class=\\"cm-property\\">person</span><span class=\\"cm-punctuation\\">(</span><span class=\\"cm-attribute\\">id</span><span class=\\"cm-punctuation\\">:</span><span class=\\"cm-ws\\"> </span><span class=\\"cm-number\\">4</span><span class=\\"cm-punctuation\\">)</span><span class=\\"cm-ws\\"> </span><span class=\\"cm-punctuation\\">{</span>
<span class=\\"cm-ws\\"> </span><span class=\\"cm-property\\">name</span>
<span class=\\"cm-ws\\"> </span><span class=\\"cm-punctuation\\">}</span>
<span class=\\"cm-ws\\"> </span><span class=\\"cm-property\\">allFilms</span><span class=\\"cm-ws\\"> </span><span class=\\"cm-punctuation\\">{</span>
<span class=\\"cm-ws\\"> </span><span class=\\"cm-property\\">totalCount</span>
<span class=\\"cm-ws\\"> </span><span class=\\"cm-property\\">films</span><span class=\\"cm-ws\\"> </span><span class=\\"cm-punctuation\\">{</span>
<span class=\\"cm-ws\\"> </span><span class=\\"cm-property\\">releaseDate</span>
<span class=\\"cm-ws\\"> </span><span class=\\"cm-property\\">planetConnection</span><span class=\\"cm-ws\\"> </span><span class=\\"cm-punctuation\\">{</span>
<span class=\\"cm-ws\\"> </span><span class=\\"cm-property\\">planets</span><span class=\\"cm-ws\\"> </span><span class=\\"cm-punctuation\\">{</span>
<span class=\\"cm-ws\\"> </span><span class=\\"cm-property\\">id</span>
<span class=\\"cm-ws\\"> </span><span class=\\"cm-property\\">surfaceWater</span>
<span class=\\"cm-ws\\"> </span><span class=\\"cm-property\\">climates</span>
<span class=\\"cm-ws\\"> </span><span class=\\"cm-property\\">terrains</span>
<span class=\\"cm-ws\\"> </span><span class=\\"cm-punctuation\\">}</span>
<span class=\\"cm-ws\\"> </span><span class=\\"cm-punctuation\\">}</span>
<span class=\\"cm-ws\\"> </span><span class=\\"cm-punctuation\\">}</span>
<span class=\\"cm-ws\\"> </span><span class=\\"cm-punctuation\\">}</span>
<span class=\\"cm-punctuation\\">}</span>
</div>"
`;
exports[`Supported languages Groovy should syntax highlight an example 1`] = `
"<div class=\\"cm-s-neo\\"><span class=\\"cm-variable\\">println</span> <span class=\\"cm-string\\">&quot;Hello World&quot;</span>
</div>"
Expand Down
141 changes: 139 additions & 2 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
},
"dependencies": {
"codemirror": "^5.48.2",
"codemirror-graphql": "^1.0.2",
"prop-types": "^15.7.2",
"react-codemirror2": "^7.2.1"
},
Expand Down
1 change: 1 addition & 0 deletions src/utils/canonical.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const modeAliases = {
docker: 'dockerfile',
ecmascript: 'javascript',
erl: 'erlang',
gql: 'graphql',
gradle: 'groovy',
handlebars: 'html',
hbs: 'html',
Expand Down
1 change: 1 addition & 0 deletions src/utils/cm-mode-imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ require('codemirror/mode/sql/sql');
require('codemirror/mode/swift/swift');
require('codemirror/mode/toml/toml');
require('codemirror/mode/yaml/yaml');
require('codemirror-graphql/mode');
1 change: 1 addition & 0 deletions src/utils/modes.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const modes = {
erl: 'erlang',
go: ['go', 'text/x-go'],
gradle: 'groovy',
gql: 'graphql',
handlebars: 'htmlmixed',
hbs: 'htmlmixed',
html: 'htmlmixed',
Expand Down
2 changes: 2 additions & 0 deletions src/utils/uppercase.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ const codeTypes = {
erl: 'Erlang',
erlang: 'Erlang',
go: 'Go',
gql: 'GraphQL',
gradle: 'Gradle',
graphql: 'GraphQL',
groovy: 'Groovy',
handlebars: 'Handlebars',
hbs: 'Handlebars',
Expand Down

0 comments on commit 8ffcb52

Please sign in to comment.