diff --git a/src/legacy/core_plugins/console/public/quarantined/src/sense_editor/mode/input_highlight_rules.js b/src/legacy/core_plugins/console/public/quarantined/src/sense_editor/mode/input_highlight_rules.js index 17c1e3876f076..a80ab73a80d22 100644 --- a/src/legacy/core_plugins/console/public/quarantined/src/sense_editor/mode/input_highlight_rules.js +++ b/src/legacy/core_plugins/console/public/quarantined/src/sense_editor/mode/input_highlight_rules.js @@ -42,11 +42,6 @@ export function InputHighlightRules() { // regexps are ordered -> the first match is used /*jshint -W015 */ this.$rules = { - 'start-sql': [ - { token: 'whitespace', regex: '\\s+' }, - { token: 'paren.lparen', regex: '{', next: 'json-sql', push: true }, - { regex: '', next: 'start' } - ], 'start': mergeTokens([ { 'token': 'warning', 'regex': '#!.*$' }, { token: 'comment', regex: /^#.*$/ }, @@ -71,7 +66,6 @@ export function InputHighlightRules() { addEOL(['whitespace'], /(\s+)/, 'start', 'url') ), 'url': mergeTokens( - addEOL(['url.part'], /(_sql)/, 'start-sql', 'url-sql'), addEOL(['url.part'], /([^?\/,\s]+)/, 'start'), addEOL(['url.comma'], /(,)/, 'start'), addEOL(['url.slash'], /(\/)/, 'start'), @@ -82,16 +76,6 @@ export function InputHighlightRules() { addEOL(['url.param'], /([^&=]+)/, 'start'), addEOL(['url.amp'], /(&)/, 'start') ), - 'url-sql': mergeTokens( - addEOL(['url.comma'], /(,)/, 'start-sql'), - addEOL(['url.slash'], /(\/)/, 'start-sql'), - addEOL(['url.questionmark'], /(\?)/, 'start-sql', 'urlParams-sql') - ), - 'urlParams-sql': mergeTokens( - addEOL(['url.param', 'url.equal', 'url.value'], /([^&=]+)(=)([^&]*)/, 'start-sql'), - addEOL(['url.param'], /([^&=]+)/, 'start-sql'), - addEOL(['url.amp'], /(&)/, 'start-sql') - ), }; addToRules(this); diff --git a/src/legacy/core_plugins/console/public/quarantined/src/sense_editor/mode/x_json_highlight_rules.js b/src/legacy/core_plugins/console/public/quarantined/src/sense_editor/mode/x_json_highlight_rules.js index 8e39ea0acba10..f5051af1e295b 100644 --- a/src/legacy/core_plugins/console/public/quarantined/src/sense_editor/mode/x_json_highlight_rules.js +++ b/src/legacy/core_plugins/console/public/quarantined/src/sense_editor/mode/x_json_highlight_rules.js @@ -26,7 +26,7 @@ const { ScriptHighlightRules } = require('./script_highlight_rules'); const jsonRules = function (root) { root = root ? root : 'json'; const rules = {}; - const xJsonRules = [ + rules[root] = [ { token: ['variable', 'whitespace', 'ace.punctuation.colon', 'whitespace', 'punctuation.start_triple_quote'], regex: '("(?:[^"]*_)?script"|"inline"|"source")(\\s*?)(:)(\\s*?)(""")', @@ -34,6 +34,13 @@ const jsonRules = function (root) { merge: false, push: true }, + { + token: 'punctuation.start_triple_quote', + regex: '"""sql', + next: 'sql-start', + merge: false, + push: true + }, { token: 'variable', // single line regex: '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]\\s*(?=:)' @@ -110,15 +117,6 @@ const jsonRules = function (root) { } ]; - rules[root] = xJsonRules; - rules[root + '-sql'] = [{ - token: ['variable', 'whitespace', 'ace.punctuation.colon', 'whitespace', 'punctuation.start_triple_quote'], - regex: '("query")(\\s*?)(:)(\\s*?)(""")', - next: 'sql-start', - merge: false, - push: true - }].concat(xJsonRules); - rules.string_literal = [ { token: 'punctuation.end_triple_quote', diff --git a/src/legacy/core_plugins/console/public/quarantined/src/utils.js b/src/legacy/core_plugins/console/public/quarantined/src/utils.js index 5b6bd1646c300..a083f37c4c71c 100644 --- a/src/legacy/core_plugins/console/public/quarantined/src/utils.js +++ b/src/legacy/core_plugins/console/public/quarantined/src/utils.js @@ -58,13 +58,20 @@ utils.reformatData = function (data, indent) { }; }; -utils.collapseLiteralStrings = function (data) { - const splitData = data.split(`"""`); - for (let idx = 1; idx < splitData.length - 1; idx += 2) { - splitData[idx] = JSON.stringify(splitData[idx]); +// For now just a dumb removal of any """sql strings. Eventually we want some why to reverse +// this operation can probably bundle A -> B with the B -> A functionality. +const collapseXLangMarkers = text => text.replace(`"""sql`, `"""`); + +utils.collapseLiteralStrings = _.pipe( + collapseXLangMarkers, + function (data) { + const splitData = data.split(`"""`); + for (let idx = 1; idx < splitData.length - 1; idx += 2) { + splitData[idx] = JSON.stringify(splitData[idx]); + } + return splitData.join(''); } - return splitData.join(''); -}; +); /* The following regex describes global match on: diff --git a/x-pack/legacy/plugins/console_extensions/spec/overrides/sql.query.json b/x-pack/legacy/plugins/console_extensions/spec/overrides/sql.query.json index 843fba30bb489..6373c4b756bec 100644 --- a/x-pack/legacy/plugins/console_extensions/spec/overrides/sql.query.json +++ b/x-pack/legacy/plugins/console_extensions/spec/overrides/sql.query.json @@ -4,7 +4,7 @@ "query": { "__template": { "__raw": true, - "value": "\"\"\"\nSELECT * FROM \"TABLE\"\n\"\"\"" + "value": "\"\"\"sql\nSELECT * FROM \"TABLE\"\n\"\"\"" } } }, @@ -19,6 +19,6 @@ "smile" ] }, - "template": "_sql?format=json\n{\n \"query\": \"\"\"\n SELECT * FROM \"${1:TABLE}\"\n \"\"\"\n}\n" + "template": "_sql?format=json\n{\n \"query\": \"\"\"sql\n SELECT * FROM \"${1:TABLE}\"\n \"\"\"\n}\n" } }