refactor the processing of headings to take into account the new function
parent
10e8e5e507
commit
00fef31eb2
20
index.js
20
index.js
|
@ -214,30 +214,30 @@ function parseMarkdown(doc) {
|
||||||
tree.slice(i).forEach((item) => {
|
tree.slice(i).forEach((item) => {
|
||||||
// Start iterating after Index
|
// Start iterating after Index
|
||||||
try {
|
try {
|
||||||
if (
|
|
||||||
item.type == "heading" &&
|
|
||||||
getSectionNameFromHeadingContent(item.children) == "Index"
|
|
||||||
)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (item.type == "heading") {
|
if (item.type == "heading") {
|
||||||
|
const sectionName = getSectionNameFromHeadingContent(item.children);
|
||||||
|
if (sectionName == "Index") return;
|
||||||
if (item.depth == 3) {
|
if (item.depth == 3) {
|
||||||
// Heading is an h3
|
// Heading is an h3
|
||||||
currentDepth = 3;
|
currentDepth = 3;
|
||||||
|
// create section record
|
||||||
let newSection = {
|
let newSection = {
|
||||||
section: getSectionNameFromHeadingContent(item.children),
|
section: sectionName,
|
||||||
entries: [],
|
entries: [],
|
||||||
subsections: [],
|
subsections: [],
|
||||||
};
|
};
|
||||||
sections.push(newSection); // Push the section to the output array
|
// Push the section to the output array
|
||||||
|
sections.push(newSection);
|
||||||
} else if (item.depth == 4) {
|
} else if (item.depth == 4) {
|
||||||
// Heading is an h4
|
// Heading is an h4
|
||||||
currentDepth = 4;
|
currentDepth = 4;
|
||||||
|
// create subsection record
|
||||||
let newSubsection = {
|
let newSubsection = {
|
||||||
section: getSectionNameFromHeadingContent(item.children),
|
section: sectionName,
|
||||||
entries: [],
|
entries: [],
|
||||||
};
|
};
|
||||||
sections[sections.length - 1].subsections.push(newSubsection); // Add to subsection array of most recent h3
|
// Add to subsection array of most recent h3
|
||||||
|
sections[sections.length - 1].subsections.push(newSubsection);
|
||||||
}
|
}
|
||||||
} else if (item.type == "list") {
|
} else if (item.type == "list") {
|
||||||
item.children.forEach((listItem) => {
|
item.children.forEach((listItem) => {
|
||||||
|
|
Loading…
Reference in New Issue