I was discussing with Jonah there are three flavors of BB Code I have identified from our discussion. This is the strategy pattern.
On improper nesting we can: 1 Output improper HTML, 2 Parse as much as we can safely & ignore the rest, 3 or Attempt to actually guess what the user meant. Different people will want different behavior, so when we add new behavior it should be a setting they can change, we shouldn't stop supporting the way it works now, when we add new behavior later.
I propose we support at minimum the first two, output improper HTML, or parse as much as we can safely & ignore the rest. I put a unit test for the latter, perhaps someone could write a unit test showing the ideal inputs & outputs and check it in commented out, or post the example usage scenario here, or whatever...
The 3rd strategy, trying to guess what the user meant is futile, but if you section them off to different components (classes), people can try out different strategies.
Code: Select all
function testShouldIgnoreInvalidNesting()
{
$base = new CryoBB_Base();
$base->addTag($this->tagBold());
$base->addTag($this->tagItalics());
$actual = $base->make('[b]foo[i]bar[/b][/i]');
$this->assertEqual($actual, '<strong>foo[i]bar</strong>[/i]', 'Should ignore invalid nesting');
}
PS > These forums actually try to parse bb code inside of syntax tags, thats a FAIL