Last active
August 3, 2017 08:20
-
-
Save adnanrahic/adec3f9053064c28f4ba424c0909d824 to your computer and use it in GitHub Desktop.
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
function generateSections(content) { | |
var sections = []; | |
var section = {}; | |
var subsection = {}; | |
var contentSplit = content.split('<h1>'); | |
for(index in contentSplit) { | |
if (contentSplit[index].indexOf('</h1>') !== -1) { | |
section = {}; | |
section.title = contentSplit[index].substring(0, contentSplit[index].indexOf('</h1>')); | |
contentSecondSplit = contentSplit[index].split('<h2>'); | |
for(index in contentSecondSplit) { | |
if (contentSecondSplit[index].indexOf('</h2>') !== -1) { | |
section.subsections = section.subsections || []; | |
subsection = {}; | |
subsection.title = contentSecondSplit[index].substring(0, contentSecondSplit[index].indexOf('</h2>')); | |
section.subsections.push(subsection); | |
} | |
} | |
sections.push(section); | |
} | |
} | |
return sections; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment