taufik-nurrohman / parsedown-extra-plugin

Configurable Markdown to HTML converter with Parsedown Extra.
MIT License
62 stars 13 forks source link

PHP fatal error on parsing header ("#") #30

Closed BlackxSnow closed 1 year ago

BlackxSnow commented 1 year ago
PHP Fatal error:  Uncaught TypeError: Cannot access offset of type string on string in ParsedownExtraPlugin.php:395
Stack trace:
#0 ParsedownExtraPlugin.php(186): ParsedownExtraPlugin->doSetContent(Array, NULL, false, 'argument', Array)
#1 Parsedown.php(232): ParsedownExtraPlugin->blockHeader(Array, Array)
#2 Parsedown.php(39): Parsedown->lines(Array)
#3 ParsedownExtra.php(46): Parsedown->text('#test')

PHP 8.2.1 ParsedownExtraPlugin 1.3.9 ParsedownExtra 0.8.1 Parsedown 1.7.4

Produced with:

        require_once(__DIR__.'/../thirdparty/Parsedown.php');
        require_once(__DIR__.'/../thirdparty/ParsedownExtra.php');
        require_once(__DIR__.'/../thirdparty/ParsedownExtraPlugin.php');
        $Parsedown = new ParsedownExtraPlugin;

        echo $Parsedown->text("#test");

The print_r of $Element reports: Array\n(\n [name] => h1\n [text] => test\n [handler] => line\n [attributes] => Array\n (\n )\n\n)\n Where [handler] is indeed a string.

BlackxSnow commented 1 year ago

It appears that changing ParsedownExtraPlugin.php:395 from ['handler']['argument'] to ['text'] resolves this issue. I'm unsure if it causes any side effects, but Parsedown::blockHeader does not create handler/argument in its returned object.

taufik-nurrohman commented 1 year ago

What will happen if you add at least 1 space after #. Most people use that preference to distinguish between Markdown headers with hash tags that come at the start of a paragraph.

BlackxSnow commented 1 year ago

Ah I should have mentioned that, it does the same thing with or without a space.

taufik-nurrohman commented 1 year ago

Please use the exact version of ParsedownExtra 0.8.0 for now.

https://github.com/erusev/parsedown-extra/issues/152

BlackxSnow commented 1 year ago

I have the same issue as https://github.com/taufik-nurrohman/parsedown-extra-plugin/issues/29#issuecomment-1034113664, meaning 0.8.0 does not work for me.

I also haven't seen that issue with ParsedownExtra 0.8.1, so I'm not sure whether I've just not encountered it or if perhaps the index into ['text'] is actually correct (as this is what Parsedown seems to want from blockHeader, as best I understand).

taufik-nurrohman commented 1 year ago

Okay, if this is not an issue with Parsedown Extra 0.8.1 then that will be a good news for me too. With a little fix.

taufik-nurrohman commented 1 year ago

The problem is that your core Parsedown package is using 1.7 where this plugin requires you to use 1.8. Maybe your PHP version prevents you from installing the latest Parsedown package. Yes, I can use ParsedownExtra version 0.8.1 though.

Be sure to perform this task before installing:

Composer

From the file manager interface, create a composer.json file in your project folder, then add this content:

{
  "minimum-stability": "dev"
}