diff --git a/app/assets/javascripts/pretty-text/engines/markdown-it/helpers.js.es6 b/app/assets/javascripts/pretty-text/engines/markdown-it/helpers.js.es6 index 9c82b19ea86..dbd126fc056 100644 --- a/app/assets/javascripts/pretty-text/engines/markdown-it/helpers.js.es6 +++ b/app/assets/javascripts/pretty-text/engines/markdown-it/helpers.js.es6 @@ -17,10 +17,10 @@ export function inlineRegexRule(md, options) { const start = options.start.charCodeAt(0); const maxLength = (options.maxLength || 500) + 1; - return function(state) { + return function(state, silent) { const pos = state.pos; - if (state.src.charCodeAt(pos) !== start) { + if (state.src.charCodeAt(pos) !== start || silent) { return false; } @@ -34,18 +34,19 @@ export function inlineRegexRule(md, options) { // skip if in a link if (options.skipInLink && state.tokens) { - let last = state.tokens[state.tokens.length-1]; - if (last) { - if (last.type === 'link_open') { + let i; + for(i=state.tokens.length-1;i>=0;i--) { + let token = state.tokens[i]; + let type = token.type; + if (type === 'link_open' || (type === 'html_inline' && token.content.substr(0,2) === "")) { + break; } } } - const substr = state.src.slice(pos, Math.min(pos + maxLength,state.posMax)); const matches = options.matcher.exec(substr); diff --git a/spec/components/pretty_text_spec.rb b/spec/components/pretty_text_spec.rb index dde8589da27..8e4e959b676 100644 --- a/spec/components/pretty_text_spec.rb +++ b/spec/components/pretty_text_spec.rb @@ -473,7 +473,14 @@ HTML describe "tag and category links" do it "produces tag links" do Fabricate(:topic, {tags: [Fabricate(:tag, name: 'known')]}) - expect(PrettyText.cook(" #unknown::tag #known::tag")).to match_html("

#unknown::tag #known

") + + cooked = PrettyText.cook(" #unknown::tag #known::tag") + + html = <<~HTML +

#unknown::tag #known

+ HTML + + expect(cooked).to match_html(html) end # TODO does it make sense to generate hashtags for tags that are missing in action? @@ -527,7 +534,33 @@ HTML it "produces tag links" do Fabricate(:topic, {tags: [Fabricate(:tag, name: 'known')]}) - expect(PrettyText.cook("x #unknown::tag #known::tag")).to match_html("

x #unknown::tag #known

") + + cooked = PrettyText.cook(" #unknown::tag #known::tag") + + html = <<~HTML +

#unknown::tag #known

+ HTML + + expect(cooked).to eq(html.strip) + + cooked = PrettyText.cook("[`a` #known::tag here](http://somesite.com)") + + html = <<~HTML +

a #known::tag here

+ HTML + + expect(cooked).to eq(html.strip) + + cooked = PrettyText.cook("`a` #known::tag here") + + expect(cooked).to eq(html.strip) + + cooked = PrettyText.cook("test #known::tag") + html = <<~HTML +

test #known

+ HTML + + expect(cooked).to eq(html.strip) end it "can handle mixed lists" do @@ -680,6 +713,7 @@ HTML end it "supports tables" do + markdown = <<~MD | Tables | Are | Cool | | ------------- |:-------------:| -----:|