* 从 day_plans 中批量移除对某 period 的引用
(lines, sectionInfo, periodKey)
| 5548 | * 从 day_plans 中批量移除对某 period 的引用 |
| 5549 | */ |
| 5550 | function removePeriodFromDayPlans(lines, sectionInfo, periodKey) { |
| 5551 | const dayPlansLine = findChildKey(lines, sectionInfo.start, sectionInfo.end, sectionInfo.indent, 'day_plans'); |
| 5552 | if (dayPlansLine < 0) return; |
| 5553 | |
| 5554 | const dpIndent = lines[dayPlansLine].search(/\S/); |
| 5555 | const sectionEnd = findBlockEnd(lines, sectionInfo.start, sectionInfo.indent, lines.length); |
| 5556 | const dpEnd = findBlockEnd(lines, dayPlansLine, dpIndent, sectionEnd); |
| 5557 | |
| 5558 | for (let i = dayPlansLine + 1; i < dpEnd; i++) { |
| 5559 | const line = lines[i]; |
| 5560 | if (line.trim() === '' || line.trim().startsWith('#')) continue; |
| 5561 | const listMatch = line.match(/^(\s*)-\s*(\S+)\s*$/); |
| 5562 | if (listMatch && listMatch[2] === periodKey) { |
| 5563 | lines.splice(i, 1); |
| 5564 | i--; |
| 5565 | continue; |
| 5566 | } |
| 5567 | const inlineMatch = line.match(/^(\s*periods:\s*)\[([^\]]*)\]/); |
| 5568 | if (inlineMatch) { |
| 5569 | const items = inlineMatch[2].split(',').map(s => s.trim()).filter(s => { |
| 5570 | const bare = s.replace(/^["']|["']$/g, ''); |
| 5571 | return bare && bare !== periodKey; |
| 5572 | }); |
| 5573 | lines[i] = items.length > 0 |
| 5574 | ? `${inlineMatch[1]}[${items.join(', ')}]` |
| 5575 | : `${inlineMatch[1]}[]`; |
| 5576 | } |
| 5577 | } |
| 5578 | } |
| 5579 | |
| 5580 | /** |
| 5581 | * 从指定 day_plan 中移除单个 period 引用 |
no test coverage detected