From 08401697242753fbafc8bfc1d29f93fc8e2f1a3b Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Thu, 21 Aug 2025 06:00:26 +0800 Subject: [PATCH] chore(code.js): add linenos comments --- assets/js/code.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/assets/js/code.js b/assets/js/code.js index 173d8b6e..2cc852ec 100644 --- a/assets/js/code.js +++ b/assets/js/code.js @@ -56,22 +56,22 @@ async function copyCodeToClipboard(button, highlightDiv) { } function getCodeText(highlightDiv) { - const codeElement = highlightDiv.querySelector("code"); - if (!codeElement) return ""; + const codeBlock = highlightDiv.querySelector("code"); + 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) { - const lines = Array.from(contentElements).map((el) => el.textContent.replace(/\n$/, "")); - return lines.join("\n"); + if (inlineLines.length > 0) { + const cleanedLines = Array.from(inlineLines).map((line) => line.textContent.replace(/\n$/, "")); + return cleanedLines.join("\n"); } - const tableCell = highlightDiv.querySelector(".lntable .lntd:last-child code"); - if (tableCell) { - return tableCell.textContent.trim(); + if (tableCodeCell) { + return tableCodeCell.textContent.trim(); } - return codeElement.textContent.trim(); + return codeBlock.textContent.trim(); } window.addEventListener("DOMContentLoaded", (event) => {