update render

This commit is contained in:
AceDataCloud committed 2023-04-23 01:10:48 +08:00
1 parent f047c9b62f
commit 61f4fdd6ca
9 files changed
+55 -6

No files matched your search

+19
View File
@@ -8,6 +8,9 @@ import './assets/css/tailwind.css';
import dayjs from './plugins/dayjs';
import './plugins/font-awesome';
import { vLoading } from 'element-plus';
import hl from 'highlight.js';
import 'highlight.js/styles/night-owl.css';
import copyToClipboard from 'copy-to-clipboard';
console.debug('start to create app');
const app = createApp(App);
@@ -21,3 +24,19 @@ app.use(dayjs, {
app.directive('loading', vLoading);
app.mount('#app');
console.debug('app mounted');
app.directive('highlight', (el) => {
const blocks = el.querySelectorAll('pre code');
blocks.forEach((block: HTMLPreElement) => {
// create the copy button
const copy = document.createElement('button');
copy.innerHTML = i18n.global.t('common.button.copy').toString();
// add the event listener to each click
copy.addEventListener('click', () => {
copyToClipboard(block.innerText);
});
// append the copy button to each code block
block.parentElement?.prepend(copy);
hl.highlightBlock(block);
});
});