Skip to content

Commit

Permalink
added recomended break/section behavior as mentioned in arve0#8 (comm…
Browse files Browse the repository at this point in the history
  • Loading branch information
RyeNCode committed Feb 27, 2024
1 parent eb9978e commit af679b5
Showing 1 changed file with 53 additions and 2 deletions.
55 changes: 53 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ module.exports = function headerSections(md) {

for (var i = 0, l = state.tokens.length; i < l; i++) {
var token = state.tokens[i];
let keepToken = true;

// record level of nesting
if (token.type.search('heading') !== 0) {
Expand All @@ -67,8 +68,58 @@ module.exports = function headerSections(md) {
}
sections.push(section);
}

tokens.push(token);
else
{
if (token.type === 'hr') {
const lastSection = last(sections);
switch(token.markup){
case '___': //3x_
//close current section
if (last(sections)) {
keepToken = false;
closeSections(section);
}
break;
case '______': //6x_
//close all sections
if (last(sections)) {
keepToken = false;
closeAllSections();
}
break;
case '---': //3x-
//anon section
keepToken = false;
let lastHeader = 0;
if (lastSection){
lastHeader = lastSection.header;
}
var newSection = {
header: headingLevel(`h${lastHeader}`),
nesting: nestedLevel
};
tokens.push(openSection([]));
sections.push(newSection);
break;
case '***': //3x*
//split section
if (lastSection) {
keepToken = false;
closeSections(section);
var newSection = {
header: headingLevel(`h${lastSection.header}`),
nesting: nestedLevel
};
tokens.push(openSection([]));
sections.push(newSection);
}
break;
}
}

}
if (keepToken)
tokens.push(token);
} // end for every token
closeAllSections();

Expand Down

0 comments on commit af679b5

Please sign in to comment.