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

Function ensureCodeBlockToolbar

packages/app-core/src/lib/code-block-copy.ts:83–106  ·  view source on GitHub ↗
(wrapper: HTMLElement, pre: HTMLPreElement)

Source from the content-addressed store, hash-verified

81}
82
83function ensureCodeBlockToolbar(wrapper: HTMLElement, pre: HTMLPreElement): void {
84 if (wrapper.querySelector(`.${CODE_BLOCK_TOOLBAR_CLASS}`)) return
85
86 const toolbar = pre.ownerDocument.createElement('div')
87 toolbar.className = CODE_BLOCK_TOOLBAR_CLASS
88
89 const foldButton = pre.ownerDocument.createElement('button')
90 foldButton.type = 'button'
91 foldButton.className = CODE_FOLD_BUTTON_SELECTOR.slice(1)
92 foldButton.setAttribute('aria-label', 'Collapse code block')
93 foldButton.setAttribute('aria-expanded', 'true')
94 foldButton.title = 'Collapse code block'
95 foldButton.textContent = 'Fold'
96
97 const copyButton = pre.ownerDocument.createElement('button')
98 copyButton.type = 'button'
99 copyButton.className = CODE_COPY_BUTTON_SELECTOR.slice(1)
100 copyButton.setAttribute('aria-label', 'Copy code block')
101 copyButton.title = 'Copy code block'
102 copyButton.textContent = 'Copy'
103
104 toolbar.append(foldButton, copyButton)
105 wrapper.insertBefore(toolbar, pre)
106}
107
108function ensureCodeBlockSummary(wrapper: HTMLElement, code: HTMLElement): void {
109 let summary = wrapper.querySelector<HTMLElement>(`.${CODE_BLOCK_SUMMARY_CLASS}`)

Callers 1

enhanceCodeBlockCopyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected