MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / enhanceCodeBlockCopy

Function enhanceCodeBlockCopy

packages/app-core/src/lib/code-block-copy.ts:18–45  ·  view source on GitHub ↗
(
  root: ParentNode,
  options: CodeBlockEnhanceOptions = {}
)

Source from the content-addressed store, hash-verified

16}
17
18export function enhanceCodeBlockCopy(
19 root: ParentNode,
20 options: CodeBlockEnhanceOptions = {}
21): void {
22 const blocks = Array.from(root.querySelectorAll<HTMLPreElement>('pre'))
23 const storageKey = options.notePath ? codeBlockFoldStorageKey(options.notePath) : null
24 let blockIndex = 0
25
26 for (const pre of blocks) {
27 const code = pre.firstElementChild
28 if (!(code instanceof HTMLElement) || code.tagName.toLowerCase() !== 'code') {
29 continue
30 }
31
32 const index = blockIndex
33 blockIndex += 1
34 const wrapper = ensureCodeBlockWrapper(pre)
35 wrapper.setAttribute(CODE_BLOCK_INDEX_ATTR, String(index))
36 if (storageKey) wrapper.setAttribute(CODE_BLOCK_STORAGE_KEY_ATTR, storageKey)
37 else wrapper.removeAttribute(CODE_BLOCK_STORAGE_KEY_ATTR)
38
39 ensureCodeBlockToolbar(wrapper, pre)
40 ensureCodeBlockSummary(wrapper, code)
41
42 const persisted = storageKey ? readPersistedFoldState(storageKey, index) : null
43 applyCodeBlockFoldState(wrapper, persisted ?? false)
44 }
45}
46
47export function getCodeBlockTextForCopyButton(button: Element): string | null {
48 const block = button.closest(`.${CODE_BLOCK_CLASS}`)

Callers 3

NoteHoverPreviewFunction · 0.90
Preview.tsxFile · 0.90

Calls 6

codeBlockFoldStorageKeyFunction · 0.85
ensureCodeBlockWrapperFunction · 0.85
ensureCodeBlockToolbarFunction · 0.85
ensureCodeBlockSummaryFunction · 0.85
readPersistedFoldStateFunction · 0.85
applyCodeBlockFoldStateFunction · 0.85

Tested by

no test coverage detected