MCPcopy Create free account
hub / github.com/Yorick-Ryu/deep-share / getCodeBlockText

Function getCodeBlockText

scripts/injectGptButton.js:171–194  ·  view source on GitHub ↗
(codeNode)

Source from the content-addressed store, hash-verified

169 let result = '';
170
171 const getCodeBlockText = (codeNode) => {
172 let text = '';
173
174 const appendNodeText = (currentNode) => {
175 if (currentNode.nodeType === Node.TEXT_NODE) {
176 text += currentNode.textContent;
177 return;
178 }
179
180 if (currentNode.nodeType !== Node.ELEMENT_NODE) {
181 return;
182 }
183
184 if (currentNode.tagName === 'BR') {
185 text += '\n';
186 return;
187 }
188
189 currentNode.childNodes.forEach(appendNodeText);
190 };
191
192 codeNode.childNodes.forEach(appendNodeText);
193 return text.replace(/\n$/, '');
194 };
195
196 const normalizeCodeLanguage = (language) => {
197 const normalized = (language || '').trim().toLowerCase();

Callers 1

processNodeFunction · 0.85

Calls 1

replaceMethod · 0.45

Tested by

no test coverage detected