diff --git a/package.json b/package.json index 496f0c4caa..e534cc161f 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "copy-to-clipboard": "3.3.1", "date-fns": "2.16.1", "dompurify": "2.2.6", + "highlight.js": "^10.5.0", "lodash": "4.17.20", "marked": "1.2.7", "register-service-worker": "1.7.2", diff --git a/src/components/input/editor.vue b/src/components/input/editor.vue index c651bd0088..6c902aaf5e 100644 --- a/src/components/input/editor.vue +++ b/src/components/input/editor.vue @@ -329,6 +329,11 @@ export default { return `` }, }, + highlight: function(code, language) { + const hljs = require('highlight.js'); + const validLanguage = hljs.getLanguage(language) ? language : 'plaintext'; + return hljs.highlight(validLanguage, code).value; + }, }) this.preview = DOMPurify.sanitize(marked(this.text)) @@ -406,6 +411,7 @@ export default {