Skip to content

Commit

Permalink
Fix syntax highlighting (#1142)
Browse files Browse the repository at this point in the history
* Fix syntax highlighting

* Fix webpack ignore plugin
  • Loading branch information
Sébastien Nikolaou authored Nov 1, 2021
1 parent 67f272d commit 34d8860
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 25 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
*.md diff=markdown
*.php diff=php

public/*.css binary
public/*.js binary

/.github export-ignore
/art export-ignore
/tests export-ignore
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"devDependencies": {
"axios": "^0.21",
"bootstrap": "^4.5.0",
"highlight.js": "^10.4.1",
"highlight.js": "^11.3.1",
"jquery": "^3.5",
"laravel-mix": "^6.0.6",
"lodash": "^4.17.19",
Expand Down
17 changes: 16 additions & 1 deletion resources/js/components/ExceptionCodePreview.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
<script type="text/ecmascript-6">
import hljs from 'highlight.js/lib/core';
import php from 'highlight.js/lib/languages/php';
hljs.registerLanguage('php', php);
export default {
props: ['lines', 'highlightedLine'],
methods: {
highlight(line, number){
if (number == this.highlightedLine) {
return line;
}
return hljs.highlight(line, { language: 'php' }).value;
}
}
}
</script>

<template>
<pre class="code-bg px-4 mb-0 text-white">
<p v-for="(line, number) in lines"
class="mb-0"
:class="{'highlight': number == highlightedLine}"><span class="mr-4">{{number}}</span> <span>{{line}}</span></p>
:class="{'highlight': number == highlightedLine}"><span class="mr-4">{{number}}</span> <span v-html="highlight(line, number)" /></p>
</pre>
</template>

Expand Down
7 changes: 4 additions & 3 deletions resources/js/screens/queries/preview.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<script type="text/ecmascript-6">
import hljs from 'highlight.js/lib/highlight';
import hljs from 'highlight.js/lib/core';
import sql from 'highlight.js/lib/languages/sql';
import { format } from 'sql-formatter';
hljs.registerLanguage('sql', sql);
export default {
methods: {
highlightSQL() {
this.$nextTick(() => {
hljs.registerLanguage('sql', sql);
hljs.highlightBlock(this.$refs.sqlcode);
hljs.highlightElement(this.$refs.sqlcode);
});
},
formatSql(sql) {
Expand Down
2 changes: 1 addition & 1 deletion resources/sass/base.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@import 'syntaxhighlight';
@import 'node_modules/bootstrap/scss/bootstrap';
@import 'syntaxhighlight';

body {
padding-bottom: 20px;
Expand Down
30 changes: 20 additions & 10 deletions resources/sass/syntaxhighlight.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.vjs-tree {
// Fallback for missing fonts from vue-json-pretty on Ubuntu
font-family: Monaco, Menlo, Consolas, Bitstream Vera Sans Mono, monospace !important;
font-family: $font-family-monospace;

.vjs-tree__content {
border-left: 1px dotted rgba(204, 204, 204, 0.28) !important;
Expand All @@ -15,9 +14,7 @@
position: absolute;
left: -30px;
}
.vjs-value__null {
color: #a291f5 !important;
}
.vjs-value__null,
.vjs-value__number,
.vjs-value__boolean {
color: #a291f5 !important;
Expand All @@ -29,17 +26,30 @@

.hljs-keyword,
.hljs-selector-tag,
.hljs-addition {
color: #8bd72f;
.hljs-addition,
.hljs-attr {
color: #13ce66;
}

.hljs-string,
.hljs-meta .hljs-meta-string,
.hljs-doctag,
.hljs-regexp {
.hljs-meta,
.hljs-name,
.hljs-type,
.hljs-symbol,
.hljs-bullet,
.hljs-variable,
.hljs-template-tag,
.hljs-template-variable {
color: #dacb4d;
}

.hljs-comment,
.hljs-quote,
.hljs-deletion {
color: #bfcbd9;
}

.hljs-title,
.hljs-number,
.hljs-literal {
color: #a291f5 !important;
Expand Down
5 changes: 4 additions & 1 deletion webpack.mix.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,8 @@ mix.options({
'@': path.resolve(__dirname, 'resources/js/'),
},
},
plugins: [new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)],
plugins: [new webpack.IgnorePlugin({
resourceRegExp: /^\.\/locale$/,
contextRegExp: /moment$/,
})],
});

0 comments on commit 34d8860

Please sign in to comment.