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

Function getCodeBlockLanguage

scripts/injectGptButton.js:211–228  ·  view source on GitHub ↗
(preNode, codeNode)

Source from the content-addressed store, hash-verified

209 };
210
211 const getCodeBlockLanguage = (preNode, codeNode) => {
212 const classLanguage = codeNode.className.match(/language-([a-zA-Z0-9_+-]+)/)?.[1];
213 if (classLanguage) {
214 return normalizeCodeLanguage(classLanguage);
215 }
216
217 const labels = Array.from(preNode.querySelectorAll('div'))
218 .filter(element => !element.contains(codeNode))
219 .map(element => element.textContent?.trim() || '')
220 .filter(text => text && text.length <= 30 && !/复制|copy/i.test(text));
221
222 for (const label of labels) {
223 const language = normalizeCodeLanguage(label);
224 if (language) return language;
225 }
226
227 return '';
228 };
229
230 // Process all child nodes
231 const processNode = (node, indent = 0, inListItem = false, trimText = false) => {

Callers 1

processNodeFunction · 0.85

Calls 6

normalizeCodeLanguageFunction · 0.85
matchMethod · 0.80
fromMethod · 0.80
querySelectorAllMethod · 0.80
containsMethod · 0.45
testMethod · 0.45

Tested by

no test coverage detected