I'm curious, do you use an iterator (prev, next, rewind) like you did with the parser or do you use some regex callbacks to "pre-parse/fix" (I'm not sure of the name) the html<=>bbcode converter?
Just a link to the SCEditor that seems to have a pure JS html<=>bbcode converter&parser which works very well (code available on Github).
Edit: oups, it still not perfect.