for the longest time i've been talking about using an abstract syntax tree. that involves creating a lexer/parser that creates an array of tokens. those tokens are then read at runtime. i think what we want is a little different but i'm no expert on lexers.
here's an example post:
Hello Emanuele,
I am writing you to tell you about my new site: [url=https://www.elkarte.net]ElkArte[/url]. I added a lot of features:
[*]create new posts
[*]two-factor authentication
[*]bbc parsing [i]we're going to call this ForumML or [b]FML[/b] :D[/i]
ttyl,
Josh
https://www.github.com/joshuaadickerson
this will create an array (js object for brevity):
[
{node: 'text', value: 'Hello Emanuele,'},
{node: 'new line'},
{node: 'empty line'},
{node: 'text', value: 'I am writing you to tell you about my new site: '},
{node: 'tag', value: 'url',
attr: [{node: 'url', value: 'https://www.elkarte.net'}],
children: [{node: 'text', value: 'ElkArte'}]
},
{node: 'text', value: '. I added a lot of features: '},
{node: 'new line'},
// Maybe the parser should make this a new list?
{node: 'itemcode', value: '*',
children: [{node: 'text', value: 'create new posts'}]
},
{node: 'new line'},
{node: 'itemcode', value: '*',
children: [{node: 'text', value: 'two-factor authentication'}]
},
{node: 'new line'},
{node: 'itemcode', value: '*',
children: [
{node: 'text', value: 'bbc parsing '},
{node: 'tag', value: 'i', children: [
{node: 'text', 'value': 'we\'re going to call this ForumML or '},
{node: 'tag', value: 'b', children: [{node: 'text', 'value': 'FML'}]},
{node: 'emoji', 'value': ':D'},
]}
]
},
{node: 'new line'},
{node: 'empty line'},
{node: 'text', value: 'ttyl,'},
{node: 'new line'},
{node: 'text', value: 'Josh'},
{node: 'new line'},
{node: 'tag', value: 'url',
attr: [{node: 'url', value: 'https://www.github.com/joshuaadickerson'}],
children: [{node: 'text', value: 'https://www.github.com/joshuaadickerson'}]
}
]
i'm sure there's a lot that can be done to make that smaller and maybe make it faster, but i did this in this reply window and i'm not an expert. baby steps.
i'll leave that there for now and work on a formatter for forumml next.