From 103e432d55743c044cd116e6c3bcf520abad6d17 Mon Sep 17 00:00:00 2001 From: Jon Ursenbach Date: Fri, 17 Sep 2021 14:23:25 -0700 Subject: [PATCH] feat: adding highlight support for graphql --- README.md | 1 + __tests__/__fixtures__/graphql/index.js | 9 ++ __tests__/__fixtures__/graphql/sample.graphql | 19 +++ .../__snapshots__/codeMirror.test.js.snap | 23 +++ package-lock.json | 141 +++++++++++++++++- package.json | 1 + src/utils/canonical.js | 1 + src/utils/cm-mode-imports.js | 1 + src/utils/modes.js | 1 + src/utils/uppercase.js | 2 + 10 files changed, 197 insertions(+), 2 deletions(-) create mode 100644 __tests__/__fixtures__/graphql/index.js create mode 100644 __tests__/__fixtures__/graphql/sample.graphql diff --git a/README.md b/README.md index b6bc9d2..edc73e4 100644 --- a/README.md +++ b/README.md @@ -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` | diff --git a/__tests__/__fixtures__/graphql/index.js b/__tests__/__fixtures__/graphql/index.js new file mode 100644 index 0000000..a26ec94 --- /dev/null +++ b/__tests__/__fixtures__/graphql/index.js @@ -0,0 +1,9 @@ +module.exports = { + language: 'GraphQL', + mode: { + primary: 'graphql', + aliases: { + gql: 'GraphQL', + }, + }, +}; diff --git a/__tests__/__fixtures__/graphql/sample.graphql b/__tests__/__fixtures__/graphql/sample.graphql new file mode 100644 index 0000000..8560739 --- /dev/null +++ b/__tests__/__fixtures__/graphql/sample.graphql @@ -0,0 +1,19 @@ +{ + person(id: 4) { + name + } + allFilms { + totalCount + films { + releaseDate + planetConnection { + planets { + id + surfaceWater + climates + terrains + } + } + } + } +} diff --git a/__tests__/__snapshots__/codeMirror.test.js.snap b/__tests__/__snapshots__/codeMirror.test.js.snap index 1b0e94f..b4298ce 100644 --- a/__tests__/__snapshots__/codeMirror.test.js.snap +++ b/__tests__/__snapshots__/codeMirror.test.js.snap @@ -112,6 +112,29 @@ exports[`Supported languages Go should syntax highlight an example 1`] = ` " `; +exports[`Supported languages GraphQL should syntax highlight an example 1`] = ` +"
{ + person(id: 4) { + name + } + allFilms { + totalCount + films { + releaseDate + planetConnection { + planets { + id + surfaceWater + climates + terrains + } + } + } + } +} +
" +`; + exports[`Supported languages Groovy should syntax highlight an example 1`] = ` "
println "Hello World"
" diff --git a/package-lock.json b/package-lock.json index f9b0dbd..0015cfa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,16 @@ { "name": "@readme/syntax-highlighter", - "version": "10.11.1", + "version": "10.12.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@readme/syntax-highlighter", - "version": "10.11.1", + "version": "10.12.0", "license": "ISC", "dependencies": { "codemirror": "^5.48.2", + "codemirror-graphql": "^1.0.2", "prop-types": "^15.7.2", "react-codemirror2": "^7.2.1" }, @@ -4368,6 +4369,19 @@ "resolved": "https://registry.npmjs.org/codemirror/-/codemirror-5.62.3.tgz", "integrity": "sha512-zZAyOfN8TU67ngqrxhOgtkSAGV9jSpN1snbl8elPtnh9Z5A11daR405+dhLzLnuXrwX0WCShWlybxPN3QC/9Pg==" }, + "node_modules/codemirror-graphql": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/codemirror-graphql/-/codemirror-graphql-1.0.2.tgz", + "integrity": "sha512-D4+BdYa6iQnDlio4mBk1Yap5ROCqEWapSFLkiKGatx/I0dF6euzdwd0um3Ndudw6rFQbNuT7hpcH8tnBO6VOfQ==", + "dependencies": { + "graphql-language-service-interface": "^2.8.2", + "graphql-language-service-parser": "^1.9.0" + }, + "peerDependencies": { + "codemirror": "^5.54.0", + "graphql": ">= v14.5.0 <= 15.5.0" + } + }, "node_modules/collect-v8-coverage": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/collect-v8-coverage/-/collect-v8-coverage-1.0.1.tgz", @@ -7157,6 +7171,60 @@ "integrity": "sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg==", "dev": true }, + "node_modules/graphql": { + "version": "15.5.0", + "resolved": "https://registry.npmjs.org/graphql/-/graphql-15.5.0.tgz", + "integrity": "sha512-OmaM7y0kaK31NKG31q4YbD2beNYa6jBBKtMFT6gLYJljHLJr42IqJ8KX08u3Li/0ifzTU5HjmoOOrwa5BRLeDA==", + "peer": true, + "engines": { + "node": ">= 10.x" + } + }, + "node_modules/graphql-language-service-interface": { + "version": "2.8.4", + "resolved": "https://registry.npmjs.org/graphql-language-service-interface/-/graphql-language-service-interface-2.8.4.tgz", + "integrity": "sha512-myW8z7HOZkYfhYGKDc0URFkTZChp41Po890W92zuBIhGccckgtiWSJGXaLX+r9QAwVIeZhKaNgEacsyvQb1f/g==", + "dependencies": { + "graphql-language-service-parser": "^1.9.0", + "graphql-language-service-types": "^1.8.0", + "graphql-language-service-utils": "^2.5.1", + "vscode-languageserver-types": "^3.15.1" + }, + "peerDependencies": { + "graphql": ">= v14.5.0 <= 15.5.0" + } + }, + "node_modules/graphql-language-service-parser": { + "version": "1.9.2", + "resolved": "https://registry.npmjs.org/graphql-language-service-parser/-/graphql-language-service-parser-1.9.2.tgz", + "integrity": "sha512-3txms73cJsXDfJQdR5hI83N2rpTuq9FD6aijdrXAeSuI5B60g32DxjelUkt4Ge+2BvBEDLn5ppXlpVYDC9UQHQ==", + "dependencies": { + "graphql-language-service-types": "^1.8.0" + }, + "peerDependencies": { + "graphql": ">= v14.5.0 <= 15.5.0" + } + }, + "node_modules/graphql-language-service-types": { + "version": "1.8.2", + "resolved": "https://registry.npmjs.org/graphql-language-service-types/-/graphql-language-service-types-1.8.2.tgz", + "integrity": "sha512-Sj07RHnMwAhEvAt7Jdt1l/x56ZpoNh+V6g+T58CF6GiYqI5l4vXqqRB4d4xHDcNQX98GpJfnf3o8BqPgP3C5Sw==", + "peerDependencies": { + "graphql": ">= v14.5.0 <= 15.5.0" + } + }, + "node_modules/graphql-language-service-utils": { + "version": "2.5.3", + "resolved": "https://registry.npmjs.org/graphql-language-service-utils/-/graphql-language-service-utils-2.5.3.tgz", + "integrity": "sha512-ydevEZ0AgzEKQF3hiCbLXuS0o7189Ww/T30WtCKCLaRHDYk9Yyb2PZWdhSTWLxYZTaX2TccV6NtFWvzIC7UP3g==", + "dependencies": { + "graphql-language-service-types": "^1.8.0", + "nullthrows": "^1.0.0" + }, + "peerDependencies": { + "graphql": ">= v14.5.0 <= 15.5.0" + } + }, "node_modules/handle-thing": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/handle-thing/-/handle-thing-2.0.1.tgz", @@ -10600,6 +10668,11 @@ "boolbase": "~1.0.0" } }, + "node_modules/nullthrows": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/nullthrows/-/nullthrows-1.1.1.tgz", + "integrity": "sha512-2vPPEi+Z7WqML2jZYddDIfy5Dqb0r2fze2zTxNNknZaFpVHU3mFB3R+DWeJWGVx0ecvttSGlJTI+WG+8Z4cDWw==" + }, "node_modules/number-is-nan": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", @@ -13800,6 +13873,11 @@ "extsprintf": "^1.2.0" } }, + "node_modules/vscode-languageserver-types": { + "version": "3.16.0", + "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.16.0.tgz", + "integrity": "sha512-k8luDIWJWyenLc5ToFQQMaSrqCHiLwyKPHKPQZ5zz21vM+vIVUSvsRpcbiECH4WR88K2XZqc4ScRcZ7nk/jbeA==" + }, "node_modules/w3c-hr-time": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/w3c-hr-time/-/w3c-hr-time-1.0.2.tgz", @@ -17842,6 +17920,15 @@ "resolved": "https://registry.npmjs.org/codemirror/-/codemirror-5.62.3.tgz", "integrity": "sha512-zZAyOfN8TU67ngqrxhOgtkSAGV9jSpN1snbl8elPtnh9Z5A11daR405+dhLzLnuXrwX0WCShWlybxPN3QC/9Pg==" }, + "codemirror-graphql": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/codemirror-graphql/-/codemirror-graphql-1.0.2.tgz", + "integrity": "sha512-D4+BdYa6iQnDlio4mBk1Yap5ROCqEWapSFLkiKGatx/I0dF6euzdwd0um3Ndudw6rFQbNuT7hpcH8tnBO6VOfQ==", + "requires": { + "graphql-language-service-interface": "^2.8.2", + "graphql-language-service-parser": "^1.9.0" + } + }, "collect-v8-coverage": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/collect-v8-coverage/-/collect-v8-coverage-1.0.1.tgz", @@ -20079,6 +20166,46 @@ "integrity": "sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg==", "dev": true }, + "graphql": { + "version": "15.5.0", + "resolved": "https://registry.npmjs.org/graphql/-/graphql-15.5.0.tgz", + "integrity": "sha512-OmaM7y0kaK31NKG31q4YbD2beNYa6jBBKtMFT6gLYJljHLJr42IqJ8KX08u3Li/0ifzTU5HjmoOOrwa5BRLeDA==", + "peer": true + }, + "graphql-language-service-interface": { + "version": "2.8.4", + "resolved": "https://registry.npmjs.org/graphql-language-service-interface/-/graphql-language-service-interface-2.8.4.tgz", + "integrity": "sha512-myW8z7HOZkYfhYGKDc0URFkTZChp41Po890W92zuBIhGccckgtiWSJGXaLX+r9QAwVIeZhKaNgEacsyvQb1f/g==", + "requires": { + "graphql-language-service-parser": "^1.9.0", + "graphql-language-service-types": "^1.8.0", + "graphql-language-service-utils": "^2.5.1", + "vscode-languageserver-types": "^3.15.1" + } + }, + "graphql-language-service-parser": { + "version": "1.9.2", + "resolved": "https://registry.npmjs.org/graphql-language-service-parser/-/graphql-language-service-parser-1.9.2.tgz", + "integrity": "sha512-3txms73cJsXDfJQdR5hI83N2rpTuq9FD6aijdrXAeSuI5B60g32DxjelUkt4Ge+2BvBEDLn5ppXlpVYDC9UQHQ==", + "requires": { + "graphql-language-service-types": "^1.8.0" + } + }, + "graphql-language-service-types": { + "version": "1.8.2", + "resolved": "https://registry.npmjs.org/graphql-language-service-types/-/graphql-language-service-types-1.8.2.tgz", + "integrity": "sha512-Sj07RHnMwAhEvAt7Jdt1l/x56ZpoNh+V6g+T58CF6GiYqI5l4vXqqRB4d4xHDcNQX98GpJfnf3o8BqPgP3C5Sw==", + "requires": {} + }, + "graphql-language-service-utils": { + "version": "2.5.3", + "resolved": "https://registry.npmjs.org/graphql-language-service-utils/-/graphql-language-service-utils-2.5.3.tgz", + "integrity": "sha512-ydevEZ0AgzEKQF3hiCbLXuS0o7189Ww/T30WtCKCLaRHDYk9Yyb2PZWdhSTWLxYZTaX2TccV6NtFWvzIC7UP3g==", + "requires": { + "graphql-language-service-types": "^1.8.0", + "nullthrows": "^1.0.0" + } + }, "handle-thing": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/handle-thing/-/handle-thing-2.0.1.tgz", @@ -22780,6 +22907,11 @@ "boolbase": "~1.0.0" } }, + "nullthrows": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/nullthrows/-/nullthrows-1.1.1.tgz", + "integrity": "sha512-2vPPEi+Z7WqML2jZYddDIfy5Dqb0r2fze2zTxNNknZaFpVHU3mFB3R+DWeJWGVx0ecvttSGlJTI+WG+8Z4cDWw==" + }, "number-is-nan": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", @@ -25332,6 +25464,11 @@ "extsprintf": "^1.2.0" } }, + "vscode-languageserver-types": { + "version": "3.16.0", + "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.16.0.tgz", + "integrity": "sha512-k8luDIWJWyenLc5ToFQQMaSrqCHiLwyKPHKPQZ5zz21vM+vIVUSvsRpcbiECH4WR88K2XZqc4ScRcZ7nk/jbeA==" + }, "w3c-hr-time": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/w3c-hr-time/-/w3c-hr-time-1.0.2.tgz", diff --git a/package.json b/package.json index e1673ce..00a9ec8 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ }, "dependencies": { "codemirror": "^5.48.2", + "codemirror-graphql": "^1.0.2", "prop-types": "^15.7.2", "react-codemirror2": "^7.2.1" }, diff --git a/src/utils/canonical.js b/src/utils/canonical.js index be71d90..ed88a08 100644 --- a/src/utils/canonical.js +++ b/src/utils/canonical.js @@ -13,6 +13,7 @@ const modeAliases = { docker: 'dockerfile', ecmascript: 'javascript', erl: 'erlang', + gql: 'graphql', gradle: 'groovy', handlebars: 'html', hbs: 'html', diff --git a/src/utils/cm-mode-imports.js b/src/utils/cm-mode-imports.js index db8a914..f18fc5d 100644 --- a/src/utils/cm-mode-imports.js +++ b/src/utils/cm-mode-imports.js @@ -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'); diff --git a/src/utils/modes.js b/src/utils/modes.js index 28314bb..82e6bda 100644 --- a/src/utils/modes.js +++ b/src/utils/modes.js @@ -31,6 +31,7 @@ const modes = { erl: 'erlang', go: ['go', 'text/x-go'], gradle: 'groovy', + gql: 'graphql', handlebars: 'htmlmixed', hbs: 'htmlmixed', html: 'htmlmixed', diff --git a/src/utils/uppercase.js b/src/utils/uppercase.js index 58707bb..c4b10b1 100644 --- a/src/utils/uppercase.js +++ b/src/utils/uppercase.js @@ -25,7 +25,9 @@ const codeTypes = { erl: 'Erlang', erlang: 'Erlang', go: 'Go', + gql: 'GraphQL', gradle: 'Gradle', + graphql: 'GraphQL', groovy: 'Groovy', handlebars: 'Handlebars', hbs: 'Handlebars',