I have a long string with Headers and Sub-headers. Every header is supposed to have a sub header, but the string pre-processing, does not. I need to manipulate it in such a way that every header has a Sub-header.
Every header that does not have a string has a reference point under different header. The header missing the subheader needs to grab the subheader from the reference's immediate parent/proceeding header.
Here's what it looks like:
Header 1
subheader - somedata A
text
reference-header-3
stuff in the way
Header 2
subheader - somedata B
stuff in the way
stuff in the way
Header 3
stuff in the way
stuff in the way
reference-header-5
Header 4
subheader - somedata C
some text
Header 5
more text
I need to get it to be like this:
Header 1
subheader - somedata A
text
reference-header-3
stuff in the way
Header 2
subheader - somedata B
stuff in the way
stuff in the way
Header 3
subheader - somedata A [this is copied from header 1]
stuff in the way
stuff in the way
reference-header-5
Header 4
subheader - somedata C
some text
Header 5
subheader - somedata A [this is copied from header 3]
more text
If anyone know of any string libraries that can help do this that would be awesome. I don't know how to go about this, I'm thinking of converting them to DOM elements so I can traverse them with jQuery, and then convert back. But that sounds a little icky.
Anyone know how to do this?
Thanks in advance.