FIX: mention not working after a newline (new engine)

This commit is contained in:
Sam 2017-07-07 11:06:50 -04:00
parent 7906c9ce29
commit 436b894f7a
2 changed files with 14 additions and 4 deletions

View File

@ -1,6 +1,6 @@
const regex = /^(\w[\w.-]{0,59})\b/i; 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; let pos = state.pos;
@ -11,7 +11,7 @@ function applyMentions(state, silent, isSpace, isPunctChar, mentionLookup, getUR
if (pos > 0) { if (pos > 0) {
let prev = state.src.charCodeAt(pos-1); let prev = state.src.charCodeAt(pos-1);
if (!isSpace(prev) && !isPunctChar(String.fromCharCode(prev))) { if (!isWhiteSpace(prev) && !isPunctChar(String.fromCharCode(prev))) {
return false; return false;
} }
} }
@ -78,7 +78,7 @@ export function setup(helper) {
md.inline.ruler.push('mentions', (state,silent)=> applyMentions( md.inline.ruler.push('mentions', (state,silent)=> applyMentions(
state, state,
silent, silent,
md.utils.isSpace, md.utils.isWhiteSpace,
md.utils.isPunctChar, md.utils.isPunctChar,
md.options.discourse.mentionLookup, md.options.discourse.mentionLookup,
md.options.discourse.getURL md.options.discourse.getURL

View File

@ -580,12 +580,14 @@ HTML
it "can handle mentions" do it "can handle mentions" do
Fabricate(:user, username: "sam") Fabricate(:user, username: "sam")
expect(PrettyText.cook("hi @sam! hi")).to match_html '<p>hi <a class="mention" href="/u/sam">@sam</a>! hi</p>' expect(PrettyText.cook("hi @sam! hi")).to match_html '<p>hi <a class="mention" href="/u/sam">@sam</a>! hi</p>'
expect(PrettyText.cook("hi\n@sam")).to eq("<p>hi<br>\n<a class=\"mention\" href=\"/u/sam\">@sam</a></p>")
end end
it "can handle mentions inside a hyperlink" do it "can handle mentions inside a hyperlink" do
expect(PrettyText.cook("<a> @inner</a> ")).to match_html '<p><a> @inner</a></p>' expect(PrettyText.cook("<a> @inner</a> ")).to match_html '<p><a> @inner</a></p>'
end end
it "can handle mentions inside a hyperlink" do it "can handle mentions inside a hyperlink" do
expect(PrettyText.cook("[link @inner](http://site.com)")).to match_html '<p><a href="http://site.com" rel="nofollow noopener">link @inner</a></p>' expect(PrettyText.cook("[link @inner](http://site.com)")).to match_html '<p><a href="http://site.com" rel="nofollow noopener">link @inner</a></p>'
end end
@ -651,10 +653,18 @@ HTML
it 'supports typographer' do it 'supports typographer' do
SiteSetting.enable_markdown_typographer = true SiteSetting.enable_markdown_typographer = true
expect(PrettyText.cook('(tm)')).to eq('<p>™</p>') expect(PrettyText.cook('(tm)')).to eq('<p>™</p>')
SiteSetting.enable_markdown_typographer = false SiteSetting.enable_markdown_typographer = false
expect(PrettyText.cook('(tm)')).to eq('<p>(tm)</p>') expect(PrettyText.cook('(tm)')).to eq('<p>(tm)</p>')
end end
it 'does not typographer text blocks' do
SiteSetting.enable_markdown_typographer = true
expect(PrettyText.cook('```text\n"test"\n```')).to eq('<p></p>')
end
it 'handles onebox correctly' do 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\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) expect(PrettyText.cook("http://a.com\n\nhttp://b.com").split("onebox").length).to eq(3)