@farberg/reveal-template 1.1.17 → 1.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -67,10 +67,69 @@ function extractBeginEndSnippet(code, beginMarker, endMarker) {
|
|
|
67
67
|
return out.trim();
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
function injectStyles() {
|
|
71
|
+
const style = document.createElement('style');
|
|
72
|
+
style.textContent = `
|
|
73
|
+
pre.with-copy-btn {
|
|
74
|
+
position: relative;
|
|
75
|
+
}
|
|
76
|
+
.copy-code-btn {
|
|
77
|
+
position: absolute;
|
|
78
|
+
top: 0.4em;
|
|
79
|
+
right: 0.4em;
|
|
80
|
+
padding: 0.2em 0.5em;
|
|
81
|
+
font-size: 0.75em;
|
|
82
|
+
font-family: sans-serif;
|
|
83
|
+
background: rgba(255, 255, 255, 0.15);
|
|
84
|
+
color: #ccc;
|
|
85
|
+
border: 1px solid rgba(255, 255, 255, 0.25);
|
|
86
|
+
border-radius: 4px;
|
|
87
|
+
cursor: pointer;
|
|
88
|
+
opacity: 0;
|
|
89
|
+
transition: opacity 0.15s ease, background 0.15s ease;
|
|
90
|
+
z-index: 10;
|
|
91
|
+
line-height: 1.4;
|
|
92
|
+
}
|
|
93
|
+
pre.with-copy-btn:hover .copy-code-btn {
|
|
94
|
+
opacity: 1;
|
|
95
|
+
}
|
|
96
|
+
.copy-code-btn:hover {
|
|
97
|
+
background: rgba(255, 255, 255, 0.3);
|
|
98
|
+
color: #fff;
|
|
99
|
+
}
|
|
100
|
+
.copy-code-btn.copied {
|
|
101
|
+
color: #4caf50;
|
|
102
|
+
border-color: #4caf50;
|
|
103
|
+
}
|
|
104
|
+
`;
|
|
105
|
+
document.head.appendChild(style);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function addCopyButton(preEl) {
|
|
109
|
+
preEl.classList.add('with-copy-btn');
|
|
110
|
+
const btn = document.createElement('button');
|
|
111
|
+
btn.className = 'copy-code-btn';
|
|
112
|
+
btn.textContent = 'Copy';
|
|
113
|
+
btn.addEventListener('click', () => {
|
|
114
|
+
const code = preEl.querySelector('code');
|
|
115
|
+
const text = code ? code.innerText : preEl.innerText;
|
|
116
|
+
navigator.clipboard.writeText(text).then(() => {
|
|
117
|
+
btn.textContent = 'Copied!';
|
|
118
|
+
btn.classList.add('copied');
|
|
119
|
+
setTimeout(() => {
|
|
120
|
+
btn.textContent = 'Copy';
|
|
121
|
+
btn.classList.remove('copied');
|
|
122
|
+
}, 1500);
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
preEl.appendChild(btn);
|
|
126
|
+
}
|
|
127
|
+
|
|
70
128
|
export default () => {
|
|
71
129
|
return {
|
|
72
130
|
id: 'show_code_snippets',
|
|
73
131
|
init: (deck) => {
|
|
132
|
+
injectStyles();
|
|
74
133
|
|
|
75
134
|
deck.on('ready', async () => {
|
|
76
135
|
const highlightPlugin = deck.getPlugin("highlight")
|