mirror of
https://gitee.com/butubb8/blowfish.git
synced 2025-12-05 14:17:50 +08:00
chore(code.js): add linenos comments
This commit is contained in:
@@ -56,22 +56,22 @@ async function copyCodeToClipboard(button, highlightDiv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getCodeText(highlightDiv) {
|
function getCodeText(highlightDiv) {
|
||||||
const codeElement = highlightDiv.querySelector("code");
|
const codeBlock = highlightDiv.querySelector("code");
|
||||||
if (!codeElement) return "";
|
const inlineLines = codeBlock?.querySelectorAll(".cl"); // linenos=inline
|
||||||
|
const tableCodeCell = highlightDiv?.querySelector(".lntable .lntd:last-child code"); // linenos=table
|
||||||
|
|
||||||
const contentElements = codeElement.querySelectorAll(".cl");
|
if (!codeBlock) return "";
|
||||||
|
|
||||||
if (contentElements.length > 0) {
|
if (inlineLines.length > 0) {
|
||||||
const lines = Array.from(contentElements).map((el) => el.textContent.replace(/\n$/, ""));
|
const cleanedLines = Array.from(inlineLines).map((line) => line.textContent.replace(/\n$/, ""));
|
||||||
return lines.join("\n");
|
return cleanedLines.join("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
const tableCell = highlightDiv.querySelector(".lntable .lntd:last-child code");
|
if (tableCodeCell) {
|
||||||
if (tableCell) {
|
return tableCodeCell.textContent.trim();
|
||||||
return tableCell.textContent.trim();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return codeElement.textContent.trim();
|
return codeBlock.textContent.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener("DOMContentLoaded", (event) => {
|
window.addEventListener("DOMContentLoaded", (event) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user