fix: don't add copy button if already present
This commit is contained in:
@@ -1,30 +1,15 @@
|
|||||||
let initialized = false;
|
|
||||||
|
|
||||||
export function onLoad() {
|
export function onLoad() {
|
||||||
if (initialized) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function onUpdate() {
|
export function onUpdate() {
|
||||||
if (initialized) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function onDispose() {
|
|
||||||
initialized = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function init(){
|
function init(){
|
||||||
addAnchors();
|
addAnchors();
|
||||||
addClipboard();
|
addClipboard();
|
||||||
Prism.highlightAll();
|
Prism.highlightAll();
|
||||||
initialized = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,6 +38,10 @@ function addClipboard() {
|
|||||||
const codeBlocks = document.querySelectorAll('pre');
|
const codeBlocks = document.querySelectorAll('pre');
|
||||||
|
|
||||||
codeBlocks.forEach((block) => {
|
codeBlocks.forEach((block) => {
|
||||||
|
if (block.querySelector('button.copy-button')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const button = document.createElement('button');
|
const button = document.createElement('button');
|
||||||
button.className = 'copy-button';
|
button.className = 'copy-button';
|
||||||
button.type = 'button';
|
button.type = 'button';
|
||||||
|
|||||||
Reference in New Issue
Block a user