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

Markdown failing to render id's on images #956

Closed
jmaronson opened this issue Jul 23, 2016 · 3 comments
Closed

Markdown failing to render id's on images #956

jmaronson opened this issue Jul 23, 2016 · 3 comments

Comments

@jmaronson
Copy link

jmaronson commented Jul 23, 2016

Occurs both with and without markdown extra syntax enabled. The following lines produce img elements with no id attribute:

![](image.jpg?id=someimage)
![](image.jpg){#someimage}

The problem seems to occur between the 'inlineImage()' function in ParsedownGravTrait.php#L192 and its call to 'parsedownElement(...)' which is in Medium.php#L205.

Dumping the variable '$excerpt' in ParsedownGravTrait.php before and after that function call (lines 266 & 268) shows that the id is being lost. This is from a check I did with both class and id.
Before:

array:2 [▼
  "extent" => 63
  "element" => array:2 [▼
    "name" => "img"
    "attributes" => array:5 [▼
      "src" => "/grav-fresh/test/image.jpg"
      "alt" => ""
      "title" => null
      "class" => "some-class"
      "id" => "some-id"
    ]
  ]
]

After:

array:2 [▼
  "extent" => 63
  "element" => array:2 [▼
    "name" => "img"
    "attributes" => array:2 [▼
      "class" => "some-class"
      "src" => "/grav-fresh/user/pages/02.test/image.jpg"
    ]
  ]
]

The 'parsedownElement' function has the following call signature:

public function parsedownElement($title = null, $alt = null, $class = null, $reset = true)

It does not accept an id or any other attributes besides those three.

Also, I just noticed that there are actually no unit tests for this issue. The function 'testAttributeLinks()' checks the rendering of id's, but only on links, not on images.

Thank you.

@jmaronson
Copy link
Author

As far as solutions are concerned, I'm not sure what the best option is. Either

  1. Change the parsedownElement() function in Medium.php, but then the calls to that function have to be changed for all media types (and I haven't looked at all to see what those are doing vis-à-vis this problem).
  2. Write a new parsedownElement() function in the ImageMedium.php subclass (which can call the parent method but also tack on the id).

@rhukster
Copy link
Member

I need to investigate this because it has been working fine with my test in the past.

@rhukster
Copy link
Member

Fixed in develop

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

No branches or pull requests

2 participants