Giter Club home page Giter Club logo

Comments (8)

rhukster avatar rhukster commented on July 18, 2024

Actually this might be my own fault. I'm using a Trait to override some behavior, and I think it might not be taking into account all the changes you made in 1.2.0. Debugging deeper now...

from parsedown-extra.

rhukster avatar rhukster commented on July 18, 2024

Nope, it's not me, it's caused by the separation of links and images into two methods. Basically the class is found but its lost in the chain of parent calls.

from parsedown-extra.

rhukster avatar rhukster commented on July 18, 2024

Ok, i attempted to fix this but reached an impasse.

First I had to create an inlineImage() method in ParsedownExtra as it was missing. However that is not the real issue...

The problem really occurs when things trickle back to Parsedown::inlineImage() and the $Inline element comes back from inlineLink() with the class attribute intact. However, this being the non-extra class, manually rebuilds the $Inline element ignoring the class attribute. It is at this point the class is lost.

So when $Inline is eventually returned to ParsedownExtra::inlineImage(), the class is gone, so there's no extra elements found to add.

Maybe it's a Saturday, maybe i've spent too long in front of the computer today, but i'm stuck here, and can see no simple way to resolve short of putting logic into the Parsedown::inlineImage() method to add attributes if they exist. Any resolution to this would be welcome.

from parsedown-extra.

rhukster avatar rhukster commented on July 18, 2024

Ok, so i have a fix that doesn't rebuild the Inline Image element, it merely manipulates it. This way anything extra is not lost. I don't find it particulary 'pretty', but it does work and maintains the class attributes for ParsedownExtra:

It is a change for the Parsedown::inlineImage() method.

Parsedown.php

    protected function inlineImage($excerpt)
    {
        if ( ! isset($excerpt[1]) or $excerpt[1] !== '[')
        {
            return;
        }

        $excerpt = substr($excerpt, 1);

        $Inline = $this->inlineLink($excerpt);

        $backup = $Inline;

        if ($Inline === null)
        {
            return;
        }

        $Inline['extent'] ++;

        $Inline['element']['name'] = 'img';
        $Inline['element']['attributes']['src'] = $Inline['element']['attributes']['href'];
        unset($Inline['element']['attributes']['href']);

        $Inline['element']['attributes']['alt'] = $Inline['element']['text'];
        unset($Inline['element']['text']);

        return $Inline;
    }

I hesitate to submit a pull request because I'm sure there's a nicer way to handle this.

from parsedown-extra.

rhukster avatar rhukster commented on July 18, 2024

For completeness here are my changes:

Parsedown.php - https://github.com/rhukster/parsedown/commit/03ff22c7df8e4aac3a5a309df5f6edb0685b6e0b

ParsedownExtra.php - rhukster@41dd6f7

from parsedown-extra.

erusev avatar erusev commented on July 18, 2024

That's an impressive piece of work.

I believe that the changes in Parsedown.php are sufficient .

I'm merging the pull request.

from parsedown-extra.

erusev avatar erusev commented on July 18, 2024

p.s. I'm adding Grav to Parsedown's README.

from parsedown-extra.

rhukster avatar rhukster commented on July 18, 2024

Great Thanks!

from parsedown-extra.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.