Creating a nested object from parsed bb code
I am trying to create an object in javascript from a given string which
includes some bbcode.
var bbStr = 'Text with [url=http://somelink]links and [i]nested bb
code[/i][/url].';
I need to recursively iterate through the object and transform the above
string into something like this:
var result = {
children : [
{
text : 'Text with ',
type : 'text'
},
{
children: [
{
text : 'links and ',
type : 'text'
},
{
text : 'nested bb code',
type : 'italic'
}
],
text : null,
type : 'url',
url : 'http://somelink'
},
{
text : '.',
type : 'text'
}
],
type : null,
text : null
};
Then I would send the object to a rendering function which would
recursively create canvas text from it. But I just can't get my head
around, how to form this object.
No comments:
Post a Comment