A platform for community discussion. Free, open, simple.
FEATURE: allow better fidelity for auto linkify, disable most tlds based linkify
Samee0d3f15c191
diff --git a/app/assets/javascripts/pretty-text/engines/discourse-markdown-it.js.es6 b/app/assets/javascripts/pretty-text/engines/discourse-markdown-it.js.es6index 4af5b67f08b..0565004f93c 100644--- a/app/assets/javascripts/pretty-text/engines/discourse-markdown-it.js.es6+++ b/app/assets/javascripts/pretty-text/engines/discourse-markdown-it.js.es6@@ -215,10 +215,12 @@ export function setup(opts, siteSettings, state) {html: true,breaks: opts.discourse.features.newline,xhtmlOut: false,- linkify: opts.discourse.features.linkify,+ linkify: siteSettings.enable_markdown_linkify,typographer: siteSettings.enable_markdown_typographer});+ opts.engine.linkify.tlds(siteSettings.markdown_linkify_tlds.split('|'));+setupUrlDecoding(opts.engine);setupHoister(opts.engine);setupImageDimensions(opts.engine);diff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex 7b162be31ee..cce71de7975 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -1066,6 +1066,8 @@ en:traditional_markdown_linebreaks: "Use traditional linebreaks in Markdown, which require two trailing spaces for a linebreak."enable_markdown_typographer: "Use basic typography rules to improve text readability of paragraphs of text, replaces (c) (tm) etc, with symbols, reduces number of question marks and so on"+ enable_markdown_linkify: "Automatically treat text that looks like a link as a link: www.site.com and http://site.com will be automatically linked"+ markdown_linkify_tlds: "List of top level domains that get automatically treated as links"post_undo_action_window_mins: "Number of minutes users are allowed to undo recent actions on a post (like, flag, etc)."must_approve_users: "Staff must approve all new user accounts before they are allowed to access the site. WARNING: enabling this for a live site will revoke access for existing non-staff users!"pending_users_reminder_delay: "Notify moderators if new users have been waiting for approval for longer than this many hours. Set to -1 to disable notifications."diff --git a/config/site_settings.yml b/config/site_settings.ymlindex 1b19897afcc..8d686b52aed 100644--- a/config/site_settings.yml+++ b/config/site_settings.yml@@ -531,6 +531,13 @@ posting:enable_markdown_typographer:client: truedefault: true+ enable_markdown_linkify:+ client: true+ default: true+ markdown_linkify_tlds:+ client: true+ type: list+ default: 'com|gov|net'enable_rich_text_paste:client: truedefault: falsediff --git a/lib/pretty_text.rb b/lib/pretty_text.rbindex 7655c76c8d5..fafc6c7eb40 100644--- a/lib/pretty_text.rb+++ b/lib/pretty_text.rb@@ -167,7 +167,6 @@ module PrettyText__optInput.emojiUnicodeReplacer = __emojiUnicodeReplacer;__optInput.lookupInlineOnebox = __lookupInlineOnebox;__optInput.lookupImageUrls = __lookupImageUrls;- #{opts[:linkify] == false ? "__optInput.linkify = false;" : ""}__optInput.censoredWords = #{WordWatcher.words_for_action(:censor).join('|').to_json};JSdiff --git a/spec/components/pretty_text_spec.rb b/spec/components/pretty_text_spec.rbindex 6e0ee7e0458..971d7dd6005 100644--- a/spec/components/pretty_text_spec.rb+++ b/spec/components/pretty_text_spec.rb@@ -1237,4 +1237,44 @@ HTMLend+ it "You can disable linkify" do+ md = "www.cnn.com test.it http://test.com https://test.ab https://a"+ cooked = PrettyText.cook(md)++ html = <<~HTML+ <p><a href="http://www.cnn.com" rel="nofollow noopener">www.cnn.com</a> test.it <a href="http://test.com" rel="nofollow noopener">http://test.com</a> <a href="https://test.ab" rel="nofollow noopener">https://test.ab</a> <a href="https://a" rel="nofollow noopener">https://a</a></p>+ HTML++ expect(cooked).to eq(html.strip)++ # notice how cnn.com is no longer linked but it is+ SiteSetting.markdown_linkify_tlds = "not_com|it"++ cooked = PrettyText.cook(md)+ html = <<~HTML+ <p>www.cnn.com <a href="http://test.it" rel="nofollow noopener">test.it</a> <a href="http://test.com" rel="nofollow noopener">http://test.com</a> <a href="https://test.ab" rel="nofollow noopener">https://test.ab</a> <a href="https://a" rel="nofollow noopener">https://a</a></p>+ HTML++ expect(cooked).to eq(html.strip)++ # no tlds anymore+ SiteSetting.markdown_linkify_tlds = ""++ cooked = PrettyText.cook(md)+ html = <<~HTML+ <p>www.cnn.com test.it <a href="http://test.com" rel="nofollow noopener">http://test.com</a> <a href="https://test.ab" rel="nofollow noopener">https://test.ab</a> <a href="https://a" rel="nofollow noopener">https://a</a></p>+ HTML++ expect(cooked).to eq(html.strip)++ # lastly ... what about no linkify+ SiteSetting.enable_markdown_linkify = false++ cooked = PrettyText.cook(md)++ html = <<~HTML+ <p>www.cnn.com test.it http://test.com https://test.ab https://a</p>+ HTML+ end+enddiff --git a/spec/integrity/common_mark_spec.rb b/spec/integrity/common_mark_spec.rbindex 063e6ddff92..89009866619 100644--- a/spec/integrity/common_mark_spec.rb+++ b/spec/integrity/common_mark_spec.rb@@ -27,7 +27,8 @@ describe "CommonMark" dohtml.gsub!('<hr />', '<hr>')html.gsub!(/<img([^>]+) \/>/, "<img\\1>")- cooked = PrettyText.markdown(md, sanitize: false, linkify: false)+ SiteSetting.enable_markdown_linkify = false+ cooked = PrettyText.markdown(md, sanitize: false)cooked.strip!cooked.gsub!(" class=\"lang-auto\"", '')cooked.gsub!(/<span class="hashtag">(.*)<\/span>/, "\\1")