Skip to content

Commit 1c107d7

Browse files
committed
Minore fixes
1 parent 36e7a71 commit 1c107d7

File tree

2 files changed

+34
-34
lines changed

2 files changed

+34
-34
lines changed

src/App.js

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class App extends Component {
8484

8585
updateCodeSyntaxHighlighting = () => {
8686
document.querySelectorAll("pre code").forEach((block) => {
87-
hljs.highlightBlock(block);
87+
hljs.highlightElement(block);
8888
});
8989
};
9090

@@ -105,42 +105,45 @@ class App extends Component {
105105
};
106106

107107
addCopyButtons = (clipboard) => {
108-
document.querySelectorAll("pre code").forEach(function (codeBlock) {
108+
const codeBlockElems = document.querySelectorAll("pre code");
109+
110+
if (codeBlockElems.length === 0) {
111+
return;
112+
}
113+
codeBlockElems.forEach(function (codeBlock) {
109114
var pre = codeBlock.parentNode;
110115
var prevElem = pre.previousElementSibling;
111116

112-
if (prevElem.type === "button") {
113-
return;
114-
}
115-
116-
var button = document.createElement("button");
117-
button.className = "copy-code-button";
118-
button.setAttribute("id", "copy-code-button");
119-
button.type = "button";
120-
button.innerText = "Copy";
117+
if (prevElem.type !== "button") {
118+
var button = document.createElement("button");
119+
button.className = "copy-code-button";
120+
button.setAttribute("id", "copy-code-button");
121+
button.type = "button";
122+
button.innerText = "Copy";
121123

122-
button.addEventListener("click", function () {
123-
clipboard.writeText(codeBlock.innerText).then(
124-
function () {
125-
/* Chrome doesn't seem to blur automatically,
124+
button.addEventListener("click", function () {
125+
clipboard.writeText(codeBlock.innerText).then(
126+
function () {
127+
/* Chrome doesn't seem to blur automatically,
126128
leaving the button in a focused state. */
127-
button.blur();
128-
button.innerText = "Copied!";
129-
setTimeout(function () {
130-
button.innerText = "Copy";
131-
}, 2000);
132-
},
133-
function (error) {
134-
button.innerText = "Error";
135-
}
136-
);
137-
});
129+
button.blur();
130+
button.innerText = "Copied!";
131+
setTimeout(function () {
132+
button.innerText = "Copy";
133+
}, 2000);
134+
},
135+
function (error) {
136+
button.innerText = "Error";
137+
}
138+
);
139+
});
138140

139-
if (pre.parentNode.classList.contains("highlight")) {
140-
var highlight = pre.parentNode;
141-
highlight.parentNode.insertBefore(button, highlight);
142-
} else {
143-
pre.parentNode.insertBefore(button, pre);
141+
if (pre.parentNode.classList.contains("highlight")) {
142+
var highlight = pre.parentNode;
143+
highlight.parentNode.insertBefore(button, highlight);
144+
} else {
145+
pre.parentNode.insertBefore(button, pre);
146+
}
144147
}
145148
});
146149
};

src/styles.css

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,6 @@ body {
158158
.note-list-item {
159159
height: 60px;
160160
padding: 10px 20px 0 25px;
161-
display: flex;
162-
/* border: none;
163-
border-bottom: 1px solid #dcdcde; */
164161
white-space: nowrap;
165162
text-overflow: ellipsis;
166163
overflow: hidden;

0 commit comments

Comments
 (0)