MCPcopy Create free account
hub / github.com/microsoft/Webwright / extractPythonBlocks

Function extractPythonBlocks

assets/compare_trajectory/app.js:614–641  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

612}
613
614function extractPythonBlocks(text) {
615 const blocks = [];
616 const rawText = String(text || '').trim();
617 extractCodeFences(text).forEach((fence) => {
618 const language = String(fence.language || '').toLowerCase();
619 const content = String(fence.content || '').trim();
620 if (!content) {
621 return;
622 }
623 if (language === 'python' || language === 'py' || (!language && looksLikePython(content))) {
624 blocks.push({ title: 'python fence', text: content, sourceLabel: language || 'python fence' });
625 }
626 });
627 blocks.push(...extractPythonHeredocs(text));
628 blocks.push(...extractPythonFromPatch(text));
629 if (rawText && looksLikePython(rawText)) {
630 blocks.push({ title: 'python snippet', text: rawText, sourceLabel: 'python snippet' });
631 }
632 const seen = new Set();
633 return blocks.filter((block) => {
634 const key = String(block.text || '').trim();
635 if (!key || seen.has(key)) {
636 return false;
637 }
638 seen.add(key);
639 return true;
640 });
641}
642
643function uniqueStrings(values) {
644 return Array.from(new Set((values || []).filter(Boolean)));

Callers 1

appendPythonScriptsFunction · 0.85

Calls 4

extractCodeFencesFunction · 0.85
looksLikePythonFunction · 0.85
extractPythonHeredocsFunction · 0.85
extractPythonFromPatchFunction · 0.85

Tested by

no test coverage detected