-
Notifications
You must be signed in to change notification settings - Fork 586
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[5.x] Enhance query preview when using the pgsql driver (#1486)
* Use the frameworks query grammar formatting when using laravel >= 10.x * Change highlighting based on sql dialect * Fix styleci and add an assertion for setting the driver name * Update Highligter.vue --------- Co-authored-by: Taylor Otwell <[email protected]>
- Loading branch information
1 parent
8e145db
commit 1394592
Showing
9 changed files
with
217 additions
and
62 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"/app.js": "/app.js?id=7049e92a398e816f8cd53a915eaea592", | ||
"/app.js": "/app.js?id=9a52c14de3847c3cc640ff1845ef3ed0", | ||
"/app-dark.css": "/app-dark.css?id=1ea407db56c5163ae29311f1f38eb7b9", | ||
"/app.css": "/app.css?id=de4c978567bfd90b38d186937dee5ccf" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<script type="text/ecmascript-6"> | ||
import hljs from 'highlight.js/lib/core'; | ||
import sql from 'highlight.js/lib/languages/sql'; | ||
import pgsql from 'highlight.js/lib/languages/pgsql' | ||
hljs.registerLanguage('sql', sql) | ||
hljs.registerLanguage('pgsql', pgsql) | ||
function hasValueOrEmptyAttribute(value) { | ||
return Boolean(value || value === ""); | ||
} | ||
function escapeHTML(value) { | ||
return value | ||
.replace(/&/g, '&') | ||
.replace(/</g, '<') | ||
.replace(/>/g, '>') | ||
.replace(/"/g, '"') | ||
.replace(/'/g, '''); | ||
} | ||
export default { | ||
props: ["language", "code", "autodetect"], | ||
data: function() { | ||
return { | ||
detectedLanguage: "", | ||
unknownLanguage: false | ||
}; | ||
}, | ||
computed: { | ||
className() { | ||
if (this.unknownLanguage) return ""; | ||
return "hljs " + this.detectedLanguage; | ||
}, | ||
highlighted() { | ||
if (!this.autoDetect && !hljs.getLanguage(this.language)) { | ||
console.warn(`The language "${this.language}" you specified could not be found.`); | ||
this.unknownLanguage = true; | ||
return escapeHTML(this.code); | ||
} | ||
let result = {}; | ||
if (this.autoDetect) { | ||
result = hljs.highlightAuto(this.code); | ||
this.detectedLanguage = result.language; | ||
} else { | ||
result = hljs.highlight(this.code, { language: this.language, ignoreIllegals: this.ignoreIllegals }); | ||
this.detectedLanguage = this.language; | ||
} | ||
return result.value; | ||
}, | ||
autoDetect() { | ||
return ! this.language || hasValueOrEmptyAttribute(this.autodetect); | ||
}, | ||
ignoreIllegals() { | ||
return true; | ||
} | ||
}, | ||
template: `<pre><code :class="className" v-html="highlighted"></code></pre>` | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.