(text)
| 612 | } |
| 613 | |
| 614 | function 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 | |
| 643 | function uniqueStrings(values) { |
| 644 | return Array.from(new Set((values || []).filter(Boolean))); |
no test coverage detected