A platform for community discussion. Free, open, simple.
FEATURE: support markdown rendering for embedded posts
Arpit Jalan12706c4b295d
diff --git a/app/models/topic_embed.rb b/app/models/topic_embed.rbindex 2f2b26e1952..78ad03ce232 100644--- a/app/models/topic_embed.rb+++ b/app/models/topic_embed.rb@@ -48,11 +48,17 @@ class TopicEmbed < ActiveRecord::BaseTopic.transaction doeh = EmbeddableHost.record_for_url(url)+ cook_method = if SiteSetting.embed_support_markdown+ Post.cook_methods[:regular]+ else+ Post.cook_methods[:raw_html]+ end+creator = PostCreator.new(user,title: title,raw: absolutize_urls(url, contents),skip_validations: true,- cook_method: Post.cook_methods[:raw_html],+ cook_method: cook_method,category: eh.try(:category_id))post = creator.createif post.present?diff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex 6a7c1345f75..b427a0d4abc 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -1558,6 +1558,7 @@ en:highlighted_languages: "Included syntax highlighting rules. (Warning: including too many languages may impact performance) see: https://highlightjs.org/static/demo/ for a demo"embed_truncate: "Truncate the embedded posts."+ embed_support_markdown: "Support Markdown formatting for embedded posts."allowed_href_schemes: "Schemes allowed in links in addition to http and https."embed_post_limit: "Maximum number of posts to embed."embed_username_required: "The username for topic creation is required."diff --git a/config/site_settings.yml b/config/site_settings.ymlindex 05662ce6ce9..a503701bfdb 100644--- a/config/site_settings.yml+++ b/config/site_settings.yml@@ -656,6 +656,8 @@ posting:- code-fencesembed_truncate:default: true+ embed_support_markdown:+ default: falseallowed_href_schemes:client: truedefault: ''diff --git a/spec/models/topic_embed_spec.rb b/spec/models/topic_embed_spec.rbindex 1f00c699ec0..5dec573b52f 100644--- a/spec/models/topic_embed_spec.rb+++ b/spec/models/topic_embed_spec.rb@@ -58,6 +58,19 @@ describe TopicEmbed doendend+ context "post creation supports markdown rendering" do+ before do+ SiteSetting.embed_support_markdown = true+ end++ it "works as expected" do+ post = TopicEmbed.import(user, url, title, "some random content")+ expect(post).to be_present++ # It uses regular rendering+ expect(post.cook_method).to eq(Post.cook_methods[:regular])+ end+ endendcontext '.topic_id_for_embed' do