convert markdown to json object
<p>I have a markdown file imported in a node module like this through a webpack loader</p>

<p><code>import mardownFile from './markdownfile.md'</code></p>

<p>this file is a text book with chapters separated by a ## / h2 tag</p>

<p>now, I'm looking for a way to convert this into a json object with each h2 tag (or other possible wrapper) in separate chapter chunks to use with a react page component with the page content as props.children. More details on what I'm trying to solve</p>

<p>I have this in my markdown.md file</p>

<pre><code>#Title
##Chapter 1
text text
text
##Chapter 2
text
etc
##Chapter 3
more text
image
</code></pre>

<p>I would like to read this markdown and convert it to an object, something like this...</p>

<pre><code>var aText = {
pages: [
{
 "title": "Chapter 1.",
 "text": "text",
},
{
"title": "Chapter 2.",
"text": "text",
},
{
"title": "Chapter 3.",
"text": "text",
"img": "cat-stevens.png",
}
]}
</code></pre>

<p>Then in a javascript react component render a Page component like this</p>

<p><code>&lt;Page page={aText.pages[0]} /&gt;</code></p>

<p>I'm on a mac osx computer but this is personal web client project, I was trying to parse this in a standard browser, i'm using Chrome, What's the best approach to accomplish this, any suggestions?</p>