From 9d4523b8eca138f386dbe21771b1250976396515 Mon Sep 17 00:00:00 2001 From: Jan Schulz-Hofen Date: Wed, 25 Jan 2017 16:49:30 +0100 Subject: [PATCH] Add support for @2x, @3x, etc. hires images --- app/helpers/application_helper.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 2a5acc4..b272007 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -636,7 +636,7 @@ module ApplicationHelper parse_sections(text, project, obj, attr, only_path, options) text = parse_non_pre_blocks(text, obj, macros) do |text| - [:parse_inline_attachments, :parse_wiki_links, :parse_redmine_links].each do |method_name| + [:parse_inline_attachments, :parse_hires_images, :parse_wiki_links, :parse_redmine_links].each do |method_name| send method_name, text, project, obj, attr, only_path, options end end @@ -681,6 +681,15 @@ module ApplicationHelper parsed end + # add srcset attribute to img tags if filename includes @2x, @3x, etc. + # to support hires displays + def parse_hires_images(text, project, obj, attr, only_path, options) + text.gsub!(/src="([^"]+@(\dx)\.(bmp|gif|jpg|jpe|jpeg|png))"/i) do |m| + filename, dpr = $1, $2 + m + " srcset=\"#{filename} #{dpr}\"" + end + end + def parse_inline_attachments(text, project, obj, attr, only_path, options) return if options[:inline_attachments] == false -- 2.7.2