Skip to content

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.rb
index 2f2b26e1952..78ad03ce232 100644
--- a/app/models/topic_embed.rb
+++ b/app/models/topic_embed.rb
@@ -48,11 +48,17 @@ class TopicEmbed < ActiveRecord::Base
Topic.transaction do
eh = 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.create
if post.present?
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 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.yml
index 05662ce6ce9..a503701bfdb 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -656,6 +656,8 @@ posting:
- code-fences
embed_truncate:
default: true
+ embed_support_markdown:
+ default: false
allowed_href_schemes:
client: true
default: ''
diff --git a/spec/models/topic_embed_spec.rb b/spec/models/topic_embed_spec.rb
index 1f00c699ec0..5dec573b52f 100644
--- a/spec/models/topic_embed_spec.rb
+++ b/spec/models/topic_embed_spec.rb
@@ -58,6 +58,19 @@ describe TopicEmbed do
end
end
+ 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
+ end
end
context '.topic_id_for_embed' do