Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | 377x 377x 375x 205x 2x 26x 26x 25x 25x 25x 25x 25x 25x 21x 20x 19x 17x 21x 17x 2x 7x 7x 6x 6x 1x 1x 6x 6x 6x 2x 41x 38x 38x 38x 78x 349x 6x 6x 6x 14x 14x 6x 32x 46x 46x 44x 57x 57x 44x 44x 212x 11x 11x 11x 11x 17x 17x 12x 9x 9x 12x 1x 2x 2x 12x 1x 1x 12x 11x 33x 13x | /**
* Recursively concatenates all `value` strings in an AST node tree into plain text.
*
* @param {object} node - Any AST node
* @returns {string}
*/
function flattenNodeText(node) {
try {
if (!node) return '';
if (node.type === 'text') return node.value || '';
if (node.children && Array.isArray(node.children)) return node.children.map(flattenNodeText).join('');
return node.value || '';
} catch (e) { return ''; }
}
/**
* Extracts plain text from a list item node, joining paragraph and child text
* and stripping the leading bullet character.
*
* @param {object} li - AST listItem node
* @returns {string}
*/
function extractTextFromListItem(li) {
try {
if (!li) return '';
Eif (Array.isArray(li.children)) {
const parts = [];
for (const ch of li.children) {
Iif (!ch) continue;
if (ch.type === 'paragraph' || ch.type === 'text') parts.push(flattenNodeText(ch));
else Eif (ch.children && Array.isArray(ch.children)) parts.push(ch.children.map(flattenNodeText).join(' '));
else parts.push(flattenNodeText(ch));
}
return parts.join(' ').replace(/^\s*[-\s]+/, '').trim();
}
return flattenNodeText(li).trim();
} catch (e) { return ''; }
}
/**
* Returns the first link found in an AST paragraph node, together with any
* surrounding text as the description.
*
* @param {object} node - AST paragraph node
* @returns {{ link: string, title: string|null, description: string }|null}
*/
function extractLinkFromParagraphNode(node) {
if (!node || !Array.isArray(node.children)) return null;
const linkNode = node.children.find(c => c && c.type === 'link');
if (linkNode && linkNode.url) {
const title = (linkNode.children && linkNode.children[0] && linkNode.children[0].value) || null;
const desc = node.children.filter(c => c.type === 'text').map(c => c.value).join(' ').trim();
return { link: linkNode.url, title, description: desc };
}
return null;
}
/**
* Returns the first link found in an AST list item, checking child nodes first
* then falling back to a markdown-link regex on the flattened text.
*
* @param {object} li - AST listItem node
* @returns {{ title: string|null, link: string }|null}
*/
function extractLinkFromListNode(li) {
try {
if (li && Array.isArray(li.children)) {
const linkChild = (li.children || []).flatMap(ch => (ch.children || [])).find(c => c && c.type === 'link');
if (linkChild && linkChild.url) {
const title = (linkChild.children && linkChild.children[0] && linkChild.children[0].value) || null;
return { title, link: linkChild.url };
}
}
const flat = flattenNodeText(li || '').replace(/\r?\n/g, ' ');
const mdMatch = flat.match(/\[([^\]]+)\]\(([^)]+)\)/);
if (mdMatch) return { title: mdMatch[1] || null, link: mdMatch[2] || null };
} catch (e) { /* ignore */ }
return null;
}
/**
* Finds the first section under a matching heading using a plain-text regex scan.
* Used as a fallback when the AST is not available.
*
* @param {string} text - Raw README string
* @param {RegExp[]} headingRegexes - Ordered list of regexes to match heading lines
* @returns {string|null} Section body text, or null if no heading matched
*/
function extractSectionWithRegex(text, headingRegexes) {
if (!text) return null;
try {
const lines = text.split(/\r?\n/);
for (let i = 0; i < lines.length; i++) {
for (const re of headingRegexes) {
if (re.test(lines[i])) {
const parts = [];
let j = i + 1;
while (j < lines.length && !/^#{1,6}\s+/.test(lines[j])) {
if (lines[j].trim()) parts.push(lines[j].trim());
j++;
}
return parts.length ? parts.join('\n\n') : null;
}
}
}
} catch (e) { }
return null;
}
/**
* Finds the body text of the first AST heading whose text matches any of the
* provided regexes. Stops collecting at the next heading of equal or lesser depth.
*
* @param {object} ast - Parsed README AST
* @param {RegExp[]} headingRegexes - Ordered list of regexes to match heading text
* @returns {string|null} Section body text, or null if no heading matched
*/
function findSectionText(ast, headingRegexes) {
try {
if (!ast || !Array.isArray(ast.children)) return null;
for (let i = 0; i < ast.children.length; i++) {
const n = ast.children[i];
if (n.type !== 'heading') continue;
const headingText = (flattenNodeText(n) || '').toLowerCase();
for (const re of headingRegexes) {
if (!re.test(headingText)) continue;
const depth = n.depth || 2;
let j = i + 1;
const parts = [];
while (j < ast.children.length) {
const nn = ast.children[j];
if (nn && nn.type === 'heading' && typeof nn.depth === 'number' && nn.depth <= depth) break;
if (nn.type === 'paragraph') {
const txt = (nn.children || []).map(c => c.value || '').join(' ').trim();
if (txt) parts.push(txt);
}
if (nn.type === 'list' && Array.isArray(nn.children)) {
for (const li of nn.children) {
const txt = (li.children || []).map(ch => (ch.children || []).map(cc => cc.value || '').join(' ') || ch.value || '').join(' ').trim();
Eif (txt) parts.push(txt);
}
}
if (nn.type === 'html' && typeof nn.value === 'string') {
const cleaned = nn.value.replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ').trim();
Eif (cleaned) parts.push(cleaned);
}
j++;
}
return parts.length ? parts.join('\n\n') : null;
}
}
} catch (e) { }
return null;
}
module.exports = { flattenNodeText, extractTextFromListItem, extractLinkFromParagraphNode, extractLinkFromListNode, extractSectionWithRegex, findSectionText };
|