A platform for community discussion. Free, open, simple.
FIX: improves discourse-local-dates rendering in emails
Joffrey JAFFEUX9a5aa397404e
diff --git a/plugins/discourse-local-dates/assets/javascripts/lib/discourse-markdown/discourse-local-dates.js.es6 b/plugins/discourse-local-dates/assets/javascripts/lib/discourse-markdown/discourse-local-dates.js.es6index ef46c5ca225..b6bc29ba2fa 100644--- a/plugins/discourse-local-dates/assets/javascripts/lib/discourse-markdown/discourse-local-dates.js.es6+++ b/plugins/discourse-local-dates/assets/javascripts/lib/discourse-markdown/discourse-local-dates.js.es6@@ -18,7 +18,7 @@ function addLocalDate(buffer, matches, state) {config.format = parsed.attrs.format || config.format;config.timezones = parsed.attrs.timezones || config.timezones;- token = new state.Token('a_open', 'a', 1);+ token = new state.Token('span_open', 'span', 1);token.attrs = [['class', 'discourse-local-date'],['data-date', config.date],@@ -46,19 +46,21 @@ function addLocalDate(buffer, matches, state) {}});+ token.attrs.push(['data-email-preview', previews[0]]);+token = new state.Token('text', '', 0);token.content = previews.join(", ");buffer.push(token);- token = new state.Token('a_close', 'a', -1);+ token = new state.Token('span_close', 'span', -1);buffer.push(token);}export function setup(helper) {helper.whiteList([- 'a.discourse-local-date',- 'a[data-*]',- 'a[title]'+ 'span.discourse-local-date',+ 'span[data-*]',+ 'span[title]']);helper.registerOptions((opts, siteSettings) => {diff --git a/plugins/discourse-local-dates/plugin.rb b/plugins/discourse-local-dates/plugin.rbindex e5e3348fe05..9b3f426a578 100644--- a/plugins/discourse-local-dates/plugin.rb+++ b/plugins/discourse-local-dates/plugin.rb@@ -11,4 +11,12 @@ register_asset "moment-timezone.js", :vendored_core_pretty_textenabled_site_setting :discourse_local_dates_enabled+after_initialize do+ on(:reduce_cooked) do |fragment|+ container = fragment.children[0].children[0]+ preview = container.attributes["data-email-preview"].value+ container.content = preview+ end+end+load File.expand_path('../lib/discourse_local_dates/engine.rb', __FILE__)diff --git a/plugins/discourse-local-dates/spec/lib/pretty_text_spec.rb b/plugins/discourse-local-dates/spec/lib/pretty_text_spec.rbindex 7df61b7f07b..15a9bd8dde4 100644--- a/plugins/discourse-local-dates/spec/lib/pretty_text_spec.rb+++ b/plugins/discourse-local-dates/spec/lib/pretty_text_spec.rb@@ -14,4 +14,16 @@ describe PrettyText doexpect(cooked).to include('May 8, 2018 3:00 PM (America: Los Angeles)')expect(cooked).to include('May 9, 2018 12:00 AM (Europe: Paris)')end++ it 'uses a simplified syntax in emails' do+ freeze_time+ cooked = PrettyText.cook <<~MD+ [date=2018-05-08 time=22:00 format=LLL timezones="Europe/Paris|America/Los_Angeles"]+ MD+ cooked_mail = <<~HTML+ <p><span class="discourse-local-date" data-date="2018-05-08" data-time="22:00" data-format="LLL" data-timezones="Europe/Paris|America/Los_Angeles" data-email-preview="May 9, 2018 12:00 AM (Europe: Paris)">May 9, 2018 12:00 AM (Europe: Paris)</span></p>+ HTML++ expect(PrettyText.format_for_email(cooked)).to match_html(cooked_mail)+ endend