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

Undefined index: text #152

Open
PF4Public opened this issue Apr 12, 2020 · 4 comments
Open

Undefined index: text #152

PF4Public opened this issue Apr 12, 2020 · 4 comments

Comments

@PF4Public
Copy link

At version 0.8.0 Header block had this line:

if ($Block !== null && preg_match('/[ #]*{('.$this->regexAttribute.'+)}[ ]*$/', $Block['element']['handler']['argument'], $matches, PREG_OFFSET_CAPTURE))

It was changed to this line in 0.8.1:

if (preg_match('/[ #]*{('.$this->regexAttribute.'+)}[ ]*$/', $Block['element']['text'], $matches, PREG_OFFSET_CAPTURE))

Now, with this change, it fails on custom-id with Undefined index: text. Is it a regression?

@cocochepeau
Copy link

I'm also encountering this issue.

taufik-nurrohman added a commit to mecha-cms/mecha that referenced this issue Jun 20, 2020
taufik-nurrohman added a commit to taufik-nurrohman/parsedown-extra-plugin that referenced this issue Jun 20, 2020
@casteldev
Copy link

Hi,

Using composer require erusev/parsedown-extra to install, you got the broken 0.8.1 release.
This is confusing.
0.8.1 release should be remove, I think.

@hrvoj3e
Copy link

hrvoj3e commented Mar 8, 2021

Bug or not?
These are the values of variables before preg_match.
But parent::blockHeader does not return ['element']['text'] anymore.

// $Line
array ( 'body' => '# Some title text', 'indent' => 0, 'text' => '# Some title text', )

// $Block
array ( 'element' => array ( 'name' => 'h1', 'handler' => array ( 'function' => 'lineElements', 'argument' => 'Some title text', 'destination' => 'elements', ), ), )
    protected function blockHeader($Line)
    {
        $Block = parent::blockHeader($Line);

        if (! isset($Block)) {
            return null;
        }

        if (preg_match('/[ #]*{('.$this->regexAttribute.'+)}[ ]*$/', $Block['element']['text'], $matches, PREG_OFFSET_CAPTURE))
        {
            $attributeString = $matches[1][0];
            $Block['element']['attributes'] = $this->parseAttributeData($attributeString);
            $Block['element']['text'] = substr($Block['element']['text'], 0, $matches[0][1]);
        }

        return $Block;
    }

Parsedown: 1.8.0-beta-7
ParsedownExtra: 0.8.1

Going back to ParsedownExtra: 0.8.0

@netniV
Copy link

netniV commented May 16, 2021

This is a bug, and I've documented it in my own netniV/ParsedownID#1 tracker just now... which i've copied here for completeness:

This seems to occur due to a mismatch between parsedown v1.8.0-beta7 and parse-extra v0.8.1. In the latest version of Parsedown, the blockHeader element is returned without the text attribute from the blockHeader function.

v1.7.4
$Block = array(
    'element' => array(
        'name' => 'h' . min(6, $level),
        'text' => $text,
        'handler' => 'line',
    ),
);
v1.8.0-beta7
$Block = array(
    'element' => array(
        'name' => 'h' . min(6, $level),
        'handler' => array(
            'function' => 'lineElements',
            'argument' => $text,
            'destination' => 'elements',
        )
    ),
);

I foresee that the way to correct this would be to patch parsedown-extra to see if the text element exists and if not, see if the handler is an array, thus use the argument value. Alternatively, release a 0.8.2 version that depends on the beta-7 version with the correct usage.

I have also suggested that Parsedown 1.8.0-beta7 be published as a full version now since it's not been updated in almost a year erusev/parsedown#765 (comment)

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

No branches or pull requests

5 participants