s9e / TextFormatter

Text formatting library that supports BBCode, HTML and other markup via plugins. Handles emoticons, censors words, automatically embeds media and more.
MIT License
232 stars 36 forks source link

Error on litedown plugin dealing with tabs and empty lines #73

Closed beavis closed 7 years ago

beavis commented 7 years ago

Hi, Im migrating a large database using this parser and found an error when dealing with some lines starting with tabs and no data (copy pasted from tables or excel I guess)

Example: (warning: some editors remove tabs when pasting, lines between numbers just have a tab)

$configurator = new s9e\TextFormatter\Configurator;
$configurator->Litedown;
extract($configurator->finalize());

$text = "3-3-3-3

2-2-2-2

1-1-1-1";

$xml  = $parser->parse($text);
$html = $renderer->render($xml);

echo $html;

outputs:

PHP Warning:  str_repeat(): Second argument has to be greater than or equal to 0 in xxx/vendor/s9e/text-formatter/src/Plugins/Litedown/Parser.php on line 675

Warning: str_repeat(): Second argument has to be greater than or equal to 0 in xxx/vendor/s9e/text-formatter/src/Plugins/Litedown/Parser.php on line 675
<p>3-3-3-3</p>

<pre><code>2-2-2-2

1-1-1-1</code></pre>

I would have tried to submit a pull request with a fix but not sure what's the correct behaviour on this case, all the markdown parsers I have tried just treat those lines as empty and don't add any code block. Thanks :)

JoshyPHP commented 7 years ago

Great write-up. I confirm I can reproduce the issue locally and I'm going to check it out asap.