Skip to content

A platform for community discussion. Free, open, simple.

FIX: mentions broken after adding an <abbr> tag

Samb54ba4c952d7
diff --git a/app/assets/javascripts/pretty-text/engines/discourse-markdown/helpers.js.es6 b/app/assets/javascripts/pretty-text/engines/discourse-markdown/helpers.js.es6
index 9778f5b5f2e..cd246286896 100644
--- a/app/assets/javascripts/pretty-text/engines/discourse-markdown/helpers.js.es6
+++ b/app/assets/javascripts/pretty-text/engines/discourse-markdown/helpers.js.es6
@@ -38,8 +38,12 @@ export function textReplace(state, callback, skipAllLinks) {
if (token.type === "link_open" || token.type === "link_close") {
linkLevel -= token.nesting;
} else if (token.type === "html_inline") {
- if (token.content.substr(0, 2).toLowerCase() === "<a") {
- linkLevel++;
+ const openLink = token.content.substr(0, 2).toLowerCase();
+
+ if (openLink === "<a") {
+ if (token.content.match(/^<a(\s.*)?>/i)) {
+ linkLevel++;
+ }
} else if (token.content.substr(0, 4).toLowerCase() === "</a>") {
linkLevel--;
}
diff --git a/spec/components/pretty_text_spec.rb b/spec/components/pretty_text_spec.rb
index e1a51ec510c..10fddf0e503 100644
--- a/spec/components/pretty_text_spec.rb
+++ b/spec/components/pretty_text_spec.rb
@@ -204,6 +204,10 @@ describe PrettyText do
describe "Mentions" do
+ it "can handle mentions after abbr" do
+ expect(PrettyText.cook("test <abbr>test</abbr>\n\n@bob")).to eq("<p>test <abbr>test</abbr></p>\n<p><span class=\"mention\">@bob</span></p>")
+ end
+
it "should handle 3 mentions in a row" do
expect(PrettyText.cook('@hello @hello @hello')).to match_html "<p><span class=\"mention\">@hello</span> <span class=\"mention\">@hello</span> <span class=\"mention\">@hello</span></p>"
end