[Execute UI] Added syntax highlight to JSON and shell snippets.

This commit is contained in:
Fabio Manganiello 2023-10-13 23:12:04 +02:00
parent 8b9ac59167
commit 891e05a219
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774
6 changed files with 72 additions and 12 deletions

View file

@ -11,6 +11,7 @@
"@fortawesome/fontawesome-free": "^6.1.1", "@fortawesome/fontawesome-free": "^6.1.1",
"axios": "^0.21.4", "axios": "^0.21.4",
"core-js": "^3.23.4", "core-js": "^3.23.4",
"highlight.js": "^11.9.0",
"lato-font": "^3.0.0", "lato-font": "^3.0.0",
"mitt": "^2.1.0", "mitt": "^2.1.0",
"register-service-worker": "^1.7.2", "register-service-worker": "^1.7.2",
@ -4339,6 +4340,15 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/cli-highlight/node_modules/highlight.js": {
"version": "10.7.3",
"resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-10.7.3.tgz",
"integrity": "sha512-tzcUFauisWKNHaRkN4Wjl/ZA07gENAjFl3J/c480dprkGTg5EQstgaNFqBfUqCq54kZRIEcreTsAgF/m2quD7A==",
"dev": true,
"engines": {
"node": "*"
}
},
"node_modules/cli-highlight/node_modules/supports-color": { "node_modules/cli-highlight/node_modules/supports-color": {
"version": "7.2.0", "version": "7.2.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
@ -6917,12 +6927,11 @@
} }
}, },
"node_modules/highlight.js": { "node_modules/highlight.js": {
"version": "10.7.3", "version": "11.9.0",
"resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-10.7.3.tgz", "resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-11.9.0.tgz",
"integrity": "sha512-tzcUFauisWKNHaRkN4Wjl/ZA07gENAjFl3J/c480dprkGTg5EQstgaNFqBfUqCq54kZRIEcreTsAgF/m2quD7A==", "integrity": "sha512-fJ7cW7fQGCYAkgv4CPfwFHrfd/cLS4Hau96JuJ+ZTOWhjnhoeN1ub1tFmALm/+lW5z4WCAuAV9bm05AP0mS6Gw==",
"dev": true,
"engines": { "engines": {
"node": "*" "node": ">=12.0.0"
} }
}, },
"node_modules/hosted-git-info": { "node_modules/hosted-git-info": {

View file

@ -11,6 +11,7 @@
"@fortawesome/fontawesome-free": "^6.1.1", "@fortawesome/fontawesome-free": "^6.1.1",
"axios": "^0.21.4", "axios": "^0.21.4",
"core-js": "^3.23.4", "core-js": "^3.23.4",
"highlight.js": "^11.9.0",
"lato-font": "^3.0.0", "lato-font": "^3.0.0",
"mitt": "^2.1.0", "mitt": "^2.1.0",
"register-service-worker": "^1.7.2", "register-service-worker": "^1.7.2",

View file

@ -8,8 +8,9 @@
<!-- cURL snippet modal --> <!-- cURL snippet modal -->
<Modal ref="curlModal" title="curl request" v-if="curlSnippet?.length"> <Modal ref="curlModal" title="curl request" v-if="curlSnippet?.length">
<textarea class="output curl-snippet" readonly :value="curlSnippet" <div class="output curl-snippet" @click="copyToClipboard(curlSnippet)" >
@click="copyToClipboard(curlSnippet)" /> <pre><code v-html="highlightedCurlSnippet" /></pre>
</div>
</Modal> </Modal>
<!-- Execute panel views --> <!-- Execute panel views -->
@ -101,6 +102,9 @@
</template> </template>
<script> <script>
import 'highlight.js/lib/common'
import 'highlight.js/styles/stackoverflow-dark.css'
import hljs from "highlight.js"
import ActionArgs from "./ActionArgs" import ActionArgs from "./ActionArgs"
import ActionDoc from "./ActionDoc" import ActionDoc from "./ActionDoc"
import Autocomplete from "@/components/elements/Autocomplete" import Autocomplete from "@/components/elements/Autocomplete"
@ -231,6 +235,14 @@ export default {
`'${this.curlURL}'` `'${this.curlURL}'`
) )
}, },
highlightedCurlSnippet() {
return hljs.highlight(
'bash',
'# Note: Replace the cookie with a JWT token for production cases\n' +
this.curlSnippet
).value
},
}, },
methods: { methods: {

View file

@ -10,8 +10,9 @@
</button> </button>
</span> </span>
</h2> </h2>
<div class="output response" v-if="response != null"> <div class="output response" v-if="response != null">
<pre v-text="response" /> <pre><code v-html="jsonResponse" v-if="jsonResponse != null" /><code v-text="response" v-else /></pre>
</div> </div>
<div class="output error" v-else-if="error != null"> <div class="output error" v-else-if="error != null">
@ -21,6 +22,9 @@
</template> </template>
<script> <script>
import 'highlight.js/lib/common'
import 'highlight.js/styles/stackoverflow-dark.css'
import hljs from "highlight.js"
import Utils from "@/Utils" import Utils from "@/Utils"
export default { export default {
@ -30,6 +34,24 @@ export default {
response: String, response: String,
error: String, error: String,
}, },
computed: {
isJSON() {
try {
return JSON.parse(this.response) != null
} catch (e) {
return false
}
},
jsonResponse() {
if (this.isJSON) {
return hljs.highlight('json', this.response).value
}
return null
}
},
} }
</script> </script>

View file

@ -1,5 +1,9 @@
@import "vars.scss"; @import "vars.scss";
main {
min-height: calc(100vh - 2em);
}
button { button {
background: none; background: none;
border: none; border: none;
@ -40,6 +44,15 @@ section {
margin-top: .5em; margin-top: .5em;
padding-top: .5em; padding-top: .5em;
} }
&.response {
flex-grow: 1;
max-height: 40em;
.output {
overflow: auto;
}
}
} }
.buttons { .buttons {
@ -58,6 +71,10 @@ header {
.autocomplete-container { .autocomplete-container {
width: calc(100% - $request-headers-btn-width); width: calc(100% - $request-headers-btn-width);
flex-grow: 1; flex-grow: 1;
.items {
background: $background-color;
}
} }
.buttons { .buttons {
@ -105,6 +122,7 @@ textarea {
form { form {
background: $default-bg-2; background: $default-bg-2;
flex-grow: 1;
margin: 0; margin: 0;
border-radius: 0; border-radius: 0;
border: none; border: none;

View file

@ -142,22 +142,20 @@ class HttpWebpagePlugin(Plugin):
and PDF. and PDF.
:return: dict :return: dict
Example if outfile is not specified:: Example return payload outfile is not specified::
{ {
"url": <url>, "url": <url>,
"title": <page title>, "title": <page title>,
"content": <page parsed content> "content": <page parsed content>
} }
Example if outfile is specified:: Example return payload if outfile is specified::
{ {
"url": <url>, "url": <url>,
"title": <page title>, "title": <page title>,
"outfile": <output file absolute path> "outfile": <output file absolute path>
} }
""" """