diff --git a/src/application/GuidanceSections.ts b/src/application/GuidanceSections.ts index ecadb1a9a85..a362c346d29 100644 --- a/src/application/GuidanceSections.ts +++ b/src/application/GuidanceSections.ts @@ -129,24 +129,20 @@ export const parseGuidanceSections = ( } const sections: GuideSection[] = []; for (const { guide, content, headings } of documents) { - const guideSections: GuideSection[] = []; - for (const [ordinal, heading] of headings.entries()) { + const guideStart = sections.length; + for (const { end, ordinal, parent, start, title } of headings) { // The next heading of any level ends this section's own text: it is // either the first subsection or the end of the whole section. - const ownEnd = headings[ordinal + 1]?.start ?? heading.end; - const section = { + const ownEnd = headings[ordinal + 1]?.start ?? end; + sections.push({ guide, ordinal, - heading: heading.title, - content: content.slice(heading.start, heading.end).trim(), - ownContent: content.slice(heading.start, ownEnd).trim(), + heading: title, + content: content.slice(start, end).trim(), + ownContent: content.slice(start, ownEnd).trim(), parent: - heading.parent === undefined - ? undefined - : guideSections[heading.parent], - }; - guideSections.push(section); - sections.push(section); + parent === undefined ? undefined : sections[guideStart + parent], + }); } } return sections;