( input: string, entryId: string, )
| 742 | } |
| 743 | |
| 744 | function findLocalMemoryEntrySection( |
| 745 | input: string, |
| 746 | entryId: string, |
| 747 | ): { |
| 748 | id: string; |
| 749 | headingLineIndex: number; |
| 750 | metaLineIndex?: number; |
| 751 | meta?: Record<string, string>; |
| 752 | } | null { |
| 753 | const lines = input.split(/\r?\n/); |
| 754 | let current: { |
| 755 | title: string; |
| 756 | headingLineIndex: number; |
| 757 | metaLineIndex?: number; |
| 758 | meta?: Record<string, string>; |
| 759 | } | null = null; |
| 760 | |
| 761 | const matchCurrent = () => { |
| 762 | if (!current) return null; |
| 763 | const id = current.meta?.id || slugId(current.title); |
| 764 | const proposalId = current.meta?.proposalId; |
| 765 | return id === entryId || proposalId === entryId ? { id, ...current } : null; |
| 766 | }; |
| 767 | |
| 768 | for (let index = 0; index < lines.length; index += 1) { |
| 769 | const line = lines[index] ?? ''; |
| 770 | const heading = /^##\s+(.+?)\s*$/.exec(line); |
| 771 | if (heading) { |
| 772 | const matched = matchCurrent(); |
| 773 | if (matched) return matched; |
| 774 | current = { title: heading[1] ?? '未命名记忆', headingLineIndex: index }; |
| 775 | continue; |
| 776 | } |
| 777 | if (!current || current.meta) continue; |
| 778 | const meta = parseMetaComment(line); |
| 779 | if (meta) { |
| 780 | current.meta = meta; |
| 781 | current.metaLineIndex = index; |
| 782 | } |
| 783 | } |
| 784 | return matchCurrent(); |
| 785 | } |
| 786 | |
| 787 | function findLocalMemoryEntryFullSection( |
| 788 | input: string, |
no test coverage detected