diff options
author | jakecastelli <38635403+jakecastelli@users.noreply.github.com> | 2023-03-25 19:11:43 +1030 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-25 08:41:43 +0000 |
commit | 94ec71d38583386047ac407908cd2d149aa9cbf0 (patch) | |
tree | 212ab0a363a759cd4b36b553c4b56652b87448d5 /tools | |
parent | a64469dcf10adb81fdc5b1e5248ce58520858761 (diff) | |
download | node-new-94ec71d38583386047ac407908cd2d149aa9cbf0.tar.gz |
tools: add button to copy code example to clipboard
PR-URL: https://github.com/nodejs/node/pull/46928
Refs: https://github.com/nodejs/node/issues/46894
Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/doc/html.mjs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/tools/doc/html.mjs b/tools/doc/html.mjs index 86df5162f5..d5dd7973e2 100644 --- a/tools/doc/html.mjs +++ b/tools/doc/html.mjs @@ -226,10 +226,13 @@ export function preprocessElements({ filename }) { const className = isJSFlavorSnippet(node) ? `language-js ${node.lang}` : `language-${node.lang}`; + const highlighted = `<code class='${className}'>${(getLanguage(node.lang || '') ? highlight(node.value, { language: node.lang }) : node).value}</code>`; node.type = 'html'; + const copyButton = '<button class="copy-button">copy</button>'; + if (isJSFlavorSnippet(node)) { const previousNode = parent.children[index - 1] || {}; const nextNode = parent.children[index + 1] || {}; @@ -253,16 +256,17 @@ export function preprocessElements({ filename }) { ' aria-label="Show modern ES modules syntax">' + previousNode.value + highlighted + + copyButton + '</pre>'; node.lang = null; previousNode.value = ''; previousNode.lang = null; } else { // Isolated JS snippet, no need to add the checkbox. - node.value = `<pre>${highlighted}</pre>`; + node.value = `<pre>${highlighted} ${copyButton}</pre>`; } } else { - node.value = `<pre>${highlighted}</pre>`; + node.value = `<pre>${highlighted} ${copyButton}</pre>`; } } else if (node.type === 'html' && common.isYAMLBlock(node.value)) { node.value = parseYAML(node.value); |