From 436b894f7ace3627bc3ef504a6c2c94329f2d4ab Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 7 Jul 2017 11:06:50 -0400 Subject: [PATCH] FIX: mention not working after a newline (new engine) --- .../pretty-text/engines/markdown-it/mentions.js.es6 | 6 +++--- spec/components/pretty_text_spec.rb | 12 +++++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/pretty-text/engines/markdown-it/mentions.js.es6 b/app/assets/javascripts/pretty-text/engines/markdown-it/mentions.js.es6 index 80b0f24ad35..602af3c15ae 100644 --- a/app/assets/javascripts/pretty-text/engines/markdown-it/mentions.js.es6 +++ b/app/assets/javascripts/pretty-text/engines/markdown-it/mentions.js.es6 @@ -1,6 +1,6 @@ const regex = /^(\w[\w.-]{0,59})\b/i; -function applyMentions(state, silent, isSpace, isPunctChar, mentionLookup, getURL) { +function applyMentions(state, silent, isWhiteSpace, isPunctChar, mentionLookup, getURL) { let pos = state.pos; @@ -11,7 +11,7 @@ function applyMentions(state, silent, isSpace, isPunctChar, mentionLookup, getUR if (pos > 0) { let prev = state.src.charCodeAt(pos-1); - if (!isSpace(prev) && !isPunctChar(String.fromCharCode(prev))) { + if (!isWhiteSpace(prev) && !isPunctChar(String.fromCharCode(prev))) { return false; } } @@ -78,7 +78,7 @@ export function setup(helper) { md.inline.ruler.push('mentions', (state,silent)=> applyMentions( state, silent, - md.utils.isSpace, + md.utils.isWhiteSpace, md.utils.isPunctChar, md.options.discourse.mentionLookup, md.options.discourse.getURL diff --git a/spec/components/pretty_text_spec.rb b/spec/components/pretty_text_spec.rb index 67924398a77..cae80012285 100644 --- a/spec/components/pretty_text_spec.rb +++ b/spec/components/pretty_text_spec.rb @@ -580,12 +580,14 @@ HTML it "can handle mentions" do Fabricate(:user, username: "sam") expect(PrettyText.cook("hi @sam! hi")).to match_html '

hi @sam! hi

' + expect(PrettyText.cook("hi\n@sam")).to eq("

hi
\n@sam

") end it "can handle mentions inside a hyperlink" do - expect(PrettyText.cook(" @inner ")).to match_html '

@inner

' + expect(PrettyText.cook(" @inner ")).to match_html '

@inner

' end + it "can handle mentions inside a hyperlink" do expect(PrettyText.cook("[link @inner](http://site.com)")).to match_html '

link @inner

' end @@ -651,10 +653,18 @@ HTML it 'supports typographer' do SiteSetting.enable_markdown_typographer = true expect(PrettyText.cook('(tm)')).to eq('

') + SiteSetting.enable_markdown_typographer = false expect(PrettyText.cook('(tm)')).to eq('

(tm)

') end + it 'does not typographer text blocks' do + + SiteSetting.enable_markdown_typographer = true + expect(PrettyText.cook('```text\n"test"\n```')).to eq('

') + + end + it 'handles onebox correctly' do expect(PrettyText.cook("http://a.com\nhttp://b.com").split("onebox").length).to eq(3) expect(PrettyText.cook("http://a.com\n\nhttp://b.com").split("onebox").length).to eq(3)