From a72a7b1cdfc70fa87f861d4bd39a5f257bfc61e1 Mon Sep 17 00:00:00 2001 From: NGPixel Date: Fri, 22 Nov 2019 16:16:31 -0500 Subject: [PATCH] fix: disable code block line break + copy button --- .babelrc | 2 +- client/themes/default/components/page.vue | 28 ++++++++++++++++++++-- package.json | 1 + yarn.lock | Bin 608286 -> 608303 bytes 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/.babelrc b/.babelrc index 54f4a124..25113692 100644 --- a/.babelrc +++ b/.babelrc @@ -20,7 +20,7 @@ [ "prismjs", { "languages": ["clike", "markup"], - "plugins": ["line-numbers", "autoloader", "normalize-whitespace"], + "plugins": ["line-numbers", "autoloader", "normalize-whitespace", "copy-to-clipboard", "toolbar"], "theme": "twilight", "css": true } diff --git a/client/themes/default/components/page.vue b/client/themes/default/components/page.vue index c555a5b6..05a94085 100644 --- a/client/themes/default/components/page.vue +++ b/client/themes/default/components/page.vue @@ -232,6 +232,7 @@ import { StatusIndicator } from 'vue-status-indicator' import Prism from 'prismjs' import { get } from 'vuex-pathify' import _ from 'lodash' +import ClipboardJS from 'clipboard' Prism.plugins.autoloader.languages_path = '/js/prism/' Prism.plugins.NormalizeWhitespace.setDefaults({ @@ -239,10 +240,34 @@ Prism.plugins.NormalizeWhitespace.setDefaults({ 'remove-indent': true, 'left-trim': true, 'right-trim': true, - 'break-lines': 160, 'remove-initial-line-feed': true, 'tabs-to-spaces': 2 }) +Prism.plugins.toolbar.registerButton('copy-to-clipboard', (env) => { + let linkCopy = document.createElement('button') + linkCopy.textContent = 'Copy' + + const clip = new ClipboardJS(linkCopy, { + text: () => { return env.code } + }) + + clip.on('success', () => { + linkCopy.textContent = 'Copied!' + resetClipboardText() + }) + clip.on('error', () => { + linkCopy.textContent = 'Press Ctrl+C to copy' + resetClipboardText() + }) + + return linkCopy + + function resetClipboardText() { + setTimeout(() => { + linkCopy.textContent = 'Copy' + }, 5000) + } +}) export default { components: { @@ -345,7 +370,6 @@ export default { } }, breadcrumbs() { - console.info(this.locale) return [{ path: '/', name: 'Home' }].concat(_.reduce(this.path.split('/'), (result, value, key) => { result.push({ path: _.get(_.last(result), 'path', `/${this.locale}`) + `/${value}`, diff --git a/package.json b/package.json index 9e6aabf9..9133354f 100644 --- a/package.json +++ b/package.json @@ -203,6 +203,7 @@ "cache-loader": "4.1.0", "chart.js": "2.9.0", "clean-webpack-plugin": "3.0.0", + "clipboard": "2.0.4", "codemirror": "5.49.2", "copy-webpack-plugin": "5.0.4", "core-js": "3.3.4", diff --git a/yarn.lock b/yarn.lock index a439fd54ce647ee177c3d24fc28b2b908f66f75e..b66852fea9eb3916b876721cc8e2012ef39a290f 100644 GIT binary patch delta 85 zcmbO?L3RBE)rJJ@o^h|UVl5;W(lJXOaraR7N5ug5GK8xP;2X#zh(?uJY j{%)UE$0X0#F4V{b#LPg<0>rF9%m&2l+l3lAc#Z=A8OezXm3;>Fo7Pf7_KC YnShuXh*^M`6^Pk@n0>o)BL~lM0OR5r8~^|S