Fixes for quirky markdown parser behaviours

Overhaul of https://github.com/discourse/discourse/pull/2579

Fixes:

- nested inline tags: [b]strong [b]stronger[/b] [/b]
- additional newlines in bbcode list tags: [ul]\n[li]item[/li]\n[/ul]
- auto-quoting when the first " is preceded by a string containing a bracket: ["text"
- garbage or unmatched quote tags within quote blocks.

And this time, I've added tests and everything passes `rake qunit:test`. :smile:
Could you use more descriptive variable names here?  At a glance I have no idea what `ep`, `sp` and `b` are?