FIX: mention not working after a newline (new engine)
This commit is contained in:
parent
7906c9ce29
commit
436b894f7a
|
@ -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
|
||||
|
|
|
@ -580,12 +580,14 @@ HTML
|
|||
it "can handle mentions" do
|
||||
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\n@sam")).to eq("<p>hi<br>\n<a class=\"mention\" href=\"/u/sam\">@sam</a></p>")
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
|
||||
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>'
|
||||
end
|
||||
|
@ -651,10 +653,18 @@ HTML
|
|||
it 'supports typographer' do
|
||||
SiteSetting.enable_markdown_typographer = true
|
||||
expect(PrettyText.cook('(tm)')).to eq('<p>™</p>')
|
||||
|
||||
SiteSetting.enable_markdown_typographer = false
|
||||
expect(PrettyText.cook('(tm)')).to eq('<p>(tm)</p>')
|
||||
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
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue