Skip to content
This repository has been archived by the owner on Feb 28, 2022. It is now read-only.

Commit

Permalink
undoing special case for sections
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnuescheler committed May 8, 2019
1 parent 9663eda commit 86f111d
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions src/html/split-sections.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,25 @@ function split({ content: { mdast = { children: [] } } }) {
// then get their index in the list of children
.map(node => mdast.children.indexOf(node));

if (dividers.length) {
// find pairwise permutations of spaces between blocks
// include the very start and end of the document
const starts = [0, ...dividers];
const ends = [...dividers, mdast.children.length];
const sections = _.zip(starts, ends)
// but filter out empty section
.filter(([start, end]) => start !== end)
// then return all nodes that are in between
.map(([start, end]) => {
// skip 'thematicBreak' nodes
const index = mdast.children[start].type === 'thematicBreak' ? start + 1 : start;
return section(between(mdast, index, end));
});
// find pairwise permutations of spaces between blocks
// include the very start and end of the document
const starts = [0, ...dividers];
const ends = [...dividers, mdast.children.length];
const sections = _.zip(starts, ends)
// but filter out empty section
.filter(([start, end]) => start !== end)
// then return all nodes that are in between
.map(([start, end]) => {
// skip 'thematicBreak' nodes
const index = mdast.children[start].type === 'thematicBreak' ? start + 1 : start;
return section(between(mdast, index, end));
});

// FIXME: dirty hack until we disable pipeline merging
for (let i = sections.length; i < mdast.children.length; i += 1) {
sections.push({ type: 'null' });
}
return { content: { sections, mdast: { children: sections } } };
} else {
return { content: { sections: [], mdast } };
// FIXME: dirty hack until we disable pipeline merging
for (let i = sections.length; i < mdast.children.length; i += 1) {
sections.push({ type: 'null' });
}
return { content: { sections, mdast: { children: sections } } };
}

module.exports = split;

0 comments on commit 86f111d

Please sign in to comment.