From 27539e15e1fb30ce44e93980a95331465b42cae2 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Wed, 26 Jul 2017 15:54:20 +0100 Subject: [PATCH] Allow whitespace around % scaler in markdown image syntax (#5000) --- .../engines/discourse-markdown-it.js.es6 | 2 +- spec/components/pretty_text_spec.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/pretty-text/engines/discourse-markdown-it.js.es6 b/app/assets/javascripts/pretty-text/engines/discourse-markdown-it.js.es6 index 6ffa5092572..1174be579c4 100644 --- a/app/assets/javascripts/pretty-text/engines/discourse-markdown-it.js.es6 +++ b/app/assets/javascripts/pretty-text/engines/discourse-markdown-it.js.es6 @@ -104,7 +104,7 @@ function setupHoister(md) { md.renderer.rules.html_raw = renderHoisted; } -const IMG_SIZE_REGEX = /^([1-9]+[0-9]*)x([1-9]+[0-9]*)(,([1-9][0-9]?)%)?$/; +const IMG_SIZE_REGEX = /^([1-9]+[0-9]*)x([1-9]+[0-9]*)(\s*,\s*([1-9][0-9]?)%)?$/; function renderImage(tokens, idx, options, env, slf) { var token = tokens[idx]; diff --git a/spec/components/pretty_text_spec.rb b/spec/components/pretty_text_spec.rb index 7853babee63..72beb51030d 100644 --- a/spec/components/pretty_text_spec.rb +++ b/spec/components/pretty_text_spec.rb @@ -970,6 +970,21 @@ HTML expect(cooked).to eq(html.strip) end + + it "allows whitespace before the percent scaler" do + cooked = PrettyText.cook <<~MD + ![|220x100, 50%](http://png.com/my.png) + ![|220x100 , 50%](http://png.com/my.png) + ![|220x100 ,50%](http://png.com/my.png) + MD + + html = <<~HTML +

+ +

+ HTML + end + end describe "inline onebox" do