From be2788b6ca61b246699e1a0bb91c00f055b5e43b Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Thu, 14 Jan 2016 14:14:50 -0800 Subject: [PATCH] Fix automatic images with absolute (or images dir missing) paths in markdown. Fixes #1755 --- .../features/automatic_image_sizes.feature | 23 +++++++++++++++---- .../source/markdown-sizes.html.markdown | 1 + .../extensions/automatic_image_sizes.rb | 2 +- 3 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 middleman-core/fixtures/automatic-image-size-app/source/markdown-sizes.html.markdown diff --git a/middleman-core/features/automatic_image_sizes.feature b/middleman-core/features/automatic_image_sizes.feature index 89f9d7a5..50a0b02e 100644 --- a/middleman-core/features/automatic_image_sizes.feature +++ b/middleman-core/features/automatic_image_sizes.feature @@ -2,15 +2,28 @@ Feature: Automatically detect and insert image dimensions into tags In order to speed up development and appease YSlow Scenario: Rendering an image with the feature disabled - Given "automatic_image_sizes" feature is "disabled" + Given a fixture app "automatic-image-size-app" + And a file named "config.rb" with: + """ + """ And the Server is running at "automatic-image-size-app" When I go to "/auto-image-sizes.html" Then I should not see "width=" And I should not see "height=" - + When I go to "/markdown-sizes.html" + Then I should not see "width=" + And I should not see "height=" + Scenario: Rendering an image with the feature enabled - Given "automatic_image_sizes" feature is "enabled" + Given a fixture app "automatic-image-size-app" + And a file named "config.rb" with: + """ + activate :automatic_image_sizes + """ And the Server is running at "automatic-image-size-app" When I go to "/auto-image-sizes.html" - Then I should see "width=" - And I should see "height=" \ No newline at end of file + Then I should see 'width="1"' + And I should see 'height="1"' + When I go to "/markdown-sizes.html" + Then I should see 'width="1"' + And I should see 'height="1"' diff --git a/middleman-core/fixtures/automatic-image-size-app/source/markdown-sizes.html.markdown b/middleman-core/fixtures/automatic-image-size-app/source/markdown-sizes.html.markdown new file mode 100644 index 00000000..1f9c8dcd --- /dev/null +++ b/middleman-core/fixtures/automatic-image-size-app/source/markdown-sizes.html.markdown @@ -0,0 +1 @@ +![Alt text](/images/blank.gif) diff --git a/middleman-core/lib/middleman-core/extensions/automatic_image_sizes.rb b/middleman-core/lib/middleman-core/extensions/automatic_image_sizes.rb index b88721de..5bd0f14d 100644 --- a/middleman-core/lib/middleman-core/extensions/automatic_image_sizes.rb +++ b/middleman-core/lib/middleman-core/extensions/automatic_image_sizes.rb @@ -19,7 +19,7 @@ class Middleman::Extensions::AutomaticImageSizes < ::Middleman::Extension real_path = path.dup real_path = File.join(config[:images_dir], real_path) unless real_path.start_with?('/') - file = app.files.find(:source, real_path) + file = app.files.find(:source, real_path) || app.files.find(:source, real_path.gsub(/^\//, '')) if file && file[:full_path].exist? begin