erusev / parsedown-extra

Markdown Extra Extension for Parsedown

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Undefined index: text

PF4Public opened this issue · comments

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?

I'm also encountering this issue.

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.

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

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)