Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
BlackxSnow opened this issue Feb 5, 2023 · 7 comments
Closed

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

BlackxSnow opened this issue Feb 5, 2023 · 7 comments
Labels

Comments

@BlackxSnow
Copy link

BlackxSnow commented Feb 5, 2023

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
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

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

@taufik-nurrohman
Copy link
Owner

Please use the exact version of ParsedownExtra 0.8.0 for now.

erusev/parsedown-extra#152

@BlackxSnow
Copy link
Author

I have the same issue as #29 (comment), 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
Copy link
Owner

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
Copy link
Owner

taufik-nurrohman commented Feb 18, 2023

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"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants