-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fail on false + preserving HTML blocks as single sections (#49)
* new test to fail on false * should fail on false * added divideIntoSections * fixes * fixes * some progress * fixes! * bump to 0.4.0 * fixed test * @rexagod adjustments * fixes * added fail() * fixed mostly, need to deal with edge cases * working for all but need to adjust other tests to ignore empty sections * all fixed * version bump
- Loading branch information
Showing
10 changed files
with
133 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// split by double-newline, but preserve HTML blocks as single sections: | ||
module.exports = function divideIntoSections(content) { | ||
var sections = []; | ||
content = content.replace(/[\n]{2,}/g, "\n\n"); // manage double newlines (not sure exactly?) | ||
chunkArray = content.replace(/(<(.+).*>.+<\/\2>)/g,"@@@@@@$1").split(/@@@@@@|\n\n/); | ||
|
||
chunkArray = chunkArray.filter(function (x) { | ||
return (x !== undefined && x !== '' && x.match(/\S/) !== null); // probably overzealous filtering of "empty" sections | ||
}); | ||
|
||
chunkArray.forEach(function(chunk) { | ||
if (chunk.match(/<\w>/)) { | ||
sections.push(chunk); // it's an HTML chunk | ||
} else { | ||
sections = sections.concat(chunk.split("\n\n")); // split by double newline and add | ||
} | ||
}); | ||
|
||
return sections; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters