reference: fix subheadings disappearing

This commit is contained in:
Starbeamrainbowlabs 2022-06-11 16:58:25 +01:00
parent fc4f64d25a
commit 77c634dd7d
Signed by: sbrl
GPG key ID: 1BE5172E637709C2

View file

@ -57,22 +57,25 @@ module.exports = function parse_sections(source) {
for(let line of lines) { for(let line of lines) {
if(line.startsWith(`#`)) { if(line.startsWith(`#`)) {
let heading_level = line.match(/^#+/)[0].length
// 1: Deal with the previous section // 1: Deal with the previous section
if(acc.length > 0) { if(acc.length > 0) {
let heading_level_prev = acc[0].match(/^#+/)[0].length; let heading_level_prev = acc[0].match(/^#+/)[0].length;
if(heading_level_prev === 3 && acc.length > 0) { if(heading_level_prev === 3 && acc.length > 0 && heading_level <= 3) {
result.push(make_section(acc, cat_current, cats)); result.push(make_section(acc, cat_current, cats));
} }
} }
// 2: Deal with the new line // 2: Deal with the new line
let heading_level = line.match(/^#+/)[0].length
if(heading_level === 2) if(heading_level === 2)
cat_current = extract_title(line); cat_current = extract_title(line);
if(heading_level > 3)
acc.push(line)
else
acc = [ line ]; acc = [ line ];
} }
else else