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

classes on images no longer working with 0.3.0+ #32

Closed
rhukster opened this issue Jan 11, 2015 · 8 comments
Closed

classes on images no longer working with 0.3.0+ #32

rhukster opened this issue Jan 11, 2015 · 8 comments

Comments

@rhukster
Copy link

I can't get the markdown extra syntax for extra classes to work any longer:

![](https://octodex.github.com/images/gracehoppertocat.jpg) {.github}

Results in:

<img src="https://octodex.github.com/images/gracehoppertocat.jpg" alt="">

Class is missing. This was working prior to the refactor of parsedown from 1.1.4 to 1.2.0 and the associated changes in parsedown-extra. I just is no longer available in the $excerpt.

@rhukster
Copy link
Author

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...

@rhukster
Copy link
Author

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.

@rhukster
Copy link
Author

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.

@rhukster
Copy link
Author

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.

@rhukster
Copy link
Author

For completeness here are my changes:

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

ParsedownExtra.php - rhukster@41dd6f7

@erusev
Copy link
Owner

erusev commented Jan 11, 2015

That's an impressive piece of work.

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

I'm merging the pull request.

@erusev erusev closed this as completed Jan 11, 2015
@erusev
Copy link
Owner

erusev commented Jan 11, 2015

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

@rhukster
Copy link
Author

Great Thanks!

michael-cannon added a commit to axelerant/aihrus-framework that referenced this issue Jul 16, 2015
a9dfc97 opening code fence doesn't need 2 regex groups
28774a4 improve readme
b8b5711 improve readme
9579e5f improve readme
7f7f641 improve readme
ee81967 improve readme
96e0810 improve readme
99bd1bd improve readme
e7a6a06 improve readme
eca5bb8 improve readme
1312908 improve readme
76b7d7b improve readme
ba802c1 replace the term "incomplete"
438874e improve line
8e26f45 improve readme
e2bb3ea clean up
0de61e7 improve readme
5b72dce improve readme
95699c9 improve readme
790066e improve readme
b9e5228 version 1.5.3
31c8856 Merge pull request #312 from garoevans/patch-1
d5823ad Merge pull request #295 from hkdobrev/nightly
6736ba9 Fix check against $matches
468d1e3 improve readme
7aa1d97 improve readme
f768f9c improve readme
aa83968 improve readme
85eadcc Merge pull request #297 from hkdobrev/patch-1
c94fa12 Remove "tested on PHP 5.2"
11e02d4 improve readme
ecd53f9 improve readme
844b2f4 Merge pull request #249 from HelpingHand1/patch-1
b2ad712 Test on nightly releases of PHP (7.0) and HHVM
65116c3 Merge pull request #286 from henriquemoody/travis
1470031 Remove PHP version 5.2 from Travis builds
618b260 Merge pull request #284 from jstanden/master
b828fe7 Fixes #283
6c9df52 Merge pull request #280 from kelunik/master
cb8cc57 Fixes #279
9da19c1 version 1.5.1
ffd9d3b improve tests
e94ecf4 resolve #277
4d3079b resolve #274
70e7a17 update readme
9518c8e improve readme
c581284 improve readme
cb19402 improve readme
93d0ec9 improve readme
9c6e7e8 improve readme
2d62e29 improve readme
595f338 improve readme
97e1e0e improve readme
6484194 clean up
6ddb6b2 resolve #90
0008e69 clean up
c664785 inline methods should be able to handle unmarked inline elements
bdf0ef0 setter variables should not be private
21a3e87 no need for a separate method for every special character
e5e8d02 improve order of methods
7ff0f97 improve performance
596350d improve names of elements
2cbd301 url elements should not be restricted to http
3b4aa6b change the parsing order of tag elements to improve performance
05a8f16 improve CommonMark compliance
79d9240 improve CommonMark compliance
b4a8eb3 resolve #156
4383cce resolve #143
ada3910 resolve #189
a06cdfb improve fix for #184
6bee326 resolve #184
3fe867d update readme
f08d017 resolve #196
e61a611 resolve #175
9ed72cc resolve #126
09e1184 resolve #265
2de60a9 improve readme
73a7529 improve readme
0d28808 void markup blocks be marked
78960cf improve formatting
8f2e9c7 definitions are blocks
3eb6d34 "src" and "alt" attributes should come first
859b1b1 update tests
08b01a1 blocks should be able to return markup
1686b2f we no longer call inline elements spans
15a32fc no need to know the structure of markup blocks
4aca208 update readme
cedf96a update readme
9f58363 Merge pull request #260 from rhukster/master
6b4a459 Merge pull request #261 from naNuke/master
05bf198 breaksEnabled fix
30234a5 No longer needed in this solution
03ff22c Attempted fix for stripped classes on images with ParsedownExtra - re: erusev/parsedown-extra#32
098f188 update readme
e68a458 improve consistency
86a27b4 update readme
c45dee6 update readme
06135cd improve CommonMark compliance
7d3af6b update commonmark test
dfacf7a add urlsLinked setter
fd0d812 introduce more structure to parsing of unmarked inlines
b1be886 improve names of protected members
19bc6a7 update variable names to match updated member names
b5efe98 improve names of protected members
5639ef7 fix PHPDoc
d42fcdc improve readme
d29d879 separate parsing of inlines that don't have markers to improve simplicity
c9b4de3 resolve #253
38cc1ca resolve #251
23c4097 restore support for PHP 5.2
05e8756 Merge branch 'master' of https://github.com/erusev/parsedown
ac68800 improve extensibility
1aade35 update test
361febf improve CommonMark compliance
4b7d7cd updated readme.md per comment by cebe
715f757 improve readme
907bd11 improve readme
56c6169 improve readme
97e667a Updated readme to display travis-ci.org build test
6d54fda improve readme
3b5e4e2 improve readme
85ee068 resolve #182
4c24e68 Merge remote-tracking branch 'origin/commonmark'
094cb88 update test
7ab3c60 improve CommonMark compliance
2438c1a improve output readability
46196c1 markup formatting shouldn't impact results
aa3d4d6 simplify
6fb534b improve consistency
28a202e simplify
e46be11 Merge branch 'master' into commonmark
495e7ac resolve #247
5bc6d90 resolve #248
9816507 markup should preserve empty lines
7000cbc improve readme
6df242b improve readme
f4453fd improve readme
d8011c0 improve readme
da5d75e resolve #209
2adb87e Merge pull request #236 from naNuke/escapeComment
74926c9 Add test of escaped html comment.
68f3aea Ignore html comments as well with markupEscape option.
f91e4de improve consistency
c62365a improve extensibility of test case
bb7a3f4 improve readme
f64c138 fix indents
59c77e7 improve consistency
e0965ce Merge pull request #224 from hkdobrev/no-markup-option
0a3fde3 Add `noMarkup` option to escape user HTML
d53c7db Merge pull request #221 from hkdobrev/commonmark-renaming
42222e6 Rename everything to CommonMark
e7d1600 Merge pull request #218 from hkdobrev/common-mark
ce4a29a Rename Standard Markdown to CommonMark
8ecf828 Merge pull request #217 from hkdobrev/standard-markdown
c18ff7f Add Docblock and attribution to JS test runner
6f1fac9 Add Standard Markdown testsuite.

git-subtree-dir: includes/libraries/parsedown
git-subtree-split: a9dfc97ddc06ca4739630d029bb3d2e16f3efc12
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

2 participants