FEATURE: support markdown rendering for embedded posts

This commit is contained in:
Arpit Jalan 2018-03-11 07:56:47 +05:30
parent 5316b6c6bc
commit 12706c4b29
4 changed files with 23 additions and 1 deletions

View File

@ -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?

View File

@ -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."

View File

@ -656,6 +656,8 @@ posting:
- code-fences
embed_truncate:
default: true
embed_support_markdown:
default: false
allowed_href_schemes:
client: true
default: ''

View File

@ -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