chriskonnertz / bbcode

A BBCode parser and converter written in PHP.
MIT License
40 stars 25 forks source link

More forgiving parser generating valid HTML #10

Open eazrael opened 5 years ago

eazrael commented 5 years ago

Currently I am parsing existing BBCode and you can find every possible errors. The output is this cases is not well-formed html. Any chance to get a more forgiving parser in the future?

`[img]http://cdn.edgecast.steamstatic.com/steamcommunity/public/images/clans/28666429/702d6d88139eb439facae57989a9c6633784c519.png

[/img] ` In this example, there's a new line (needed two to make github make a visible line break :( ) before the closing tag. The generated HTML looks like this:

<img src="http://cdn.edgecast.steamstatic.com/steamcommunity/public/images/clans/28666429/702d6d88139eb439facae57989a9c6633784c519.png<br/> " />

and does not pass verification (nor HTMLPurifier). due to the
in the unclosed src attribute.

Then there is this code: [url]http://store.steampowered.com/app/759750[url] The closing slash was omitted. The result is: <a href="http://store.steampowered.com/app/759750">http://store.steampowered.com/app/759750">store.steampowered.com/app/759750<a href="</a></a> /

The request is to make the HTML output standard compliant while including as much of the input as possible.

chriskonnertz commented 5 years ago

Hello,

long story told short: The current implemenation (v1.x) has some flaws by design. It was my intention to make this parser forgiving, but that's not a simple task. Already tried to rewrite it ( => https://github.com/chriskonnertz/bbcode/tree/2.0-dev ) but this is a challenging and time intensive task.

Quite frankly, I can try to fix this specific issue but I am sure you will find other problems where incorrect BBCode leads to incorrect HTML code. In my opinion it is a) impossible to avoid all of these problems or b) possible but not worth the effort with BBCode having lost most of its relevance (hi @ Markdown).

So yeah, I will try to find a solution for this specific bug but to fix all of this kind I'd have to complete v2. But I have no idea if/when this is going to happen.

eazrael commented 5 years ago

No problem, it's your time :-) Anything that can reduce erroronous output is surely a plus. Everybody makes errors and non-programmers are probably more prone to make these errors.