mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 23:09:34 +00:00
refactor(guidance): resolve parents from the section index (#17357)
This commit is contained in:
1 parent
9088c8d426
commit
f092e98c2b
1 file changed
+9
-13
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user