Closed user-none closed 5 years ago
I see what you're talking about, I can reproduce it. It's really odd; j-p-t doesn't look at anything outside of its enclosing {% %}
, so I'm baffled as to how its output is getting jumbled up with the surrounding anchor tag.
html files don't have this issue, which means it has something to do with markdown parsing. Will need further investigation. Thanks for the bug report!
I've been testing this some more, it happens even with plain HTML. With this code in a markdown file:
<a href="example.com">
<picture>
<source srcset="image.webp 1.0x, image2.webp 1.5x, image3.webp 2.0x" type="image/webp" />
<source srcset="image.jpg 1.0x, image2.jpg 1.5x, image3.jpg 2.0x" type="image/jpeg" />
<img alt="old way" src="fallback.jpg" />
</picture>
</a>
You get this output:
<p><a href="example.com"></a></p>
<picture>
<source srcset="image.webp 1.0x, image2.webp 1.5x, image3.webp 2.0x" type="image/webp" />
<source srcset="image.jpg 1.0x, image2.jpg 1.5x, image3.jpg 2.0x" type="image/jpeg" />
<img alt="old way" src="fallback.jpg" />
</picture>
<p></a></p>
Clearly kramdown doesn't know this is HTML and it shouldn't be touched. I've tried setting markdown="0"
(as well as block
) in the surrounding anchor tag, and wrapping the whole thing in {% raw %} (...) {% endraw %}
. The only workaround I can see so far is wrapping the whole thing in a <div>
tag, which convinces kramdown that it really is HTML and don't touch it.
Reading the relevant documentation hasn't gotten me anywhere, though interestingly support for <picture>
and <source>
aren't explicitly stated.
That was going to be my next step, but first I wanted to be sure it's not some mistake of mine. Thanks!
Ok, further testing shows that it's definitely an issue with kramdown:
If I create a simple test script using the same version as jekyll:
# Gemfile
source 'https://rubygems.org'
gem 'kramdown', '~>1.14'
# test.rb
require 'kramdown'
def tag
<<-HEREDOC
<a href="example.com" markdown="block">
<picture>
<source srcset="image.webp 1.0x, image2.webp 1.5x, image3.webp 2.0x" type="image/webp" />
<source srcset="image.jpg 1.0x, image2.jpg 1.5x, image3.jpg 2.0x" type="image/jpeg" />
<img alt="old way" src="fallback.jpg" />
</picture>
</a>
HEREDOC
end
puts Kramdown::Document.new(tag).to_html
I get the mangled output:
<p><a href="example.com"></a></p>
<picture>
<source srcset="image.webp 1.0x, image2.webp 1.5x, image3.webp 2.0x" type="image/webp" />
<source srcset="image.jpg 1.0x, image2.jpg 1.5x, image3.jpg 2.0x" type="image/jpeg" />
<img alt="old way" src="fallback.jpg" />
</picture>
<p></a></p>
Updating to the most recent version doesn't fix it. Removing markdown="block"
from the <a>
tag doesn't fix it.
They gave me a solution! The {::nomarkdown}
tag. This should work:
{::nomarkdown}
<a href="example.jpg">{% picture example.jpg %}</a>
{/:}
I'll write a conditional to check if it's a markdown file and insert those tags automatically. Automatic linking to the source image would be a nice feature as well, and not too difficult to add.
The plan is to detect markdown files then around the j-p-t html that's inserted you'll have it surrounded by {::nomarkdown}
?
So we'll see this after j-p-t runs but before kramdown:
[{% picture s.png %}](/images/s.png)
->
[{::nomarkdown}<picture>...</picture>{/:}](/images/s.png)
Yep, exactly. That gives a result of:
<p><a href="/images/s.png"><picture>...</picture></a></p>
But I'd also like to add a feature to automatically wrap it in an anchor tag pointing to the source image. j-p-t already has that information, there's no reason I can't add that option for you.
Fantastic! Thanks!
Problem
I wrap all of my images in a link to the full size image. Using
<img>
tag output everything works properly. However,<picture>
output is mangled.Using either markdown links or
<a>
tags directly is broken. The output is generated differently (broken in a different way) if markdown vs<a>
tags are used. I can get it working with a<div>
wrapping an<a>
and the{% picture %}
within the<a>
.I prefer to use markdown links throughout all my _posts and the
<div>
wrapper is a hack I'd rather not put thought my blog.Steps to reproduce
jekyll new myblog
_config.yml
_data/picture.yml
Input/Output
Markdown Links
generic_post.markdown
Generated HTML (BAD)
<a>
taggeneric_post_atag.markdown
Generated HTML (BAD)
Working with
<div>
wrapperThe only way I've been able to get proper links around the picture-tag images is to have a
<div>
around an<a>
tag. I have not been able to find a way to get this working with markdown links.generic_post_working.markdown
Generated HTML (Good)