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

Would it be possible to use the standard Markdown syntax for images? #15

Closed
nhoizey opened this issue Feb 24, 2016 · 5 comments
Closed

Comments

@nhoizey
Copy link

nhoizey commented Feb 24, 2016

I have put the question on StackOverflow first, so this is almost a copy/paste:

I would like to use the Jekyll Responsive Image plugin to generate appropriate responsive images with srcset/sizes attributes for my posts' images. That's why I'm here obviously… ;-)

But I would also like to be able to edit my posts in a software providing a live preview like MacDown, which only understands the standard Markdown syntax for images.

That's why I would like to know if there is a way —in this plugin or another one— to tell Jekyll to transform the standard Markdown syntax for images, which I would put in my Markdown files…

![alt text](path/to/image.jpg)

…into this syntax specific to the Jekyll Responsive Image plugin:

{% responsive_image path: path/to/image.jpg alt: "alt text" %}

And THEN, Jekyll could continue and use Kramdown to generate the HTML…

I understand I could only manage one template this way, but it should be enough for my blog.

@wildlyinaccurate
Copy link
Owner

You should be able to achieve this by writing a simple converter plugin. This should do the trick, though I don't know how performant it will be with larger sites:

module Jekyll
  class UpcaseConverter < Converter
    safe true
    priority :low

    def matches(ext)
      ext =~ /^\.md$/i
    end

    def output_ext(ext)
      ".html"
    end

    def convert(content)
      content.gsub(/\!\[(.+)\]\((.+)\)/, '{% responsive_image path: \2 alt: \1  %}')
    end
  end
end

@nhoizey
Copy link
Author

nhoizey commented Feb 25, 2016

Shouldn't the output be .md?

How does this ensure it is run before Kramdown?

@wildlyinaccurate
Copy link
Owner

output_ext is used to determine the extension of the generated file (i.e. the file in _site/). So unless you're building your site in a format other than HTML, it should probably be ".html".

If you're seeing it run after the Markdown processor, then you can bump the priority -- there's a list of priorities in the docs I linked to.

@nhoizey
Copy link
Author

nhoizey commented Feb 25, 2016

Thanks for the explanation.

It seems I could also build my converter so that it runs Kramdown after it has done its job: http://stackoverflow.com/a/26075361/717195

@nhoizey
Copy link
Author

nhoizey commented Mar 21, 2016

I think I will use @parkr 's solution: http://stackoverflow.com/a/35636071/717195

But then I still need #13 before migrating from my current use of https://github.com/nhoizey/jekyll-picture-tag

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