mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Add force_quote_link option to PrettyText (#16034)
This option will make it so the [quote] bbcode will always include the HTML link to the quoted post, even if a topic_id is not provided in the PrettyText#cook options. This is so [quote] bbcode can be used in other places, like chat messages, that always need the link and do not have an "off-topic" ID to use.
This commit is contained in:
@@ -175,6 +175,8 @@ module PrettyText
|
||||
# enabled when rendering markdown.
|
||||
# topic_id - Topic id for the post being cooked.
|
||||
# user_id - User id for the post being cooked.
|
||||
# force_quote_link - Always create the link to the quoted topic for [quote] bbcode. Normally this only happens
|
||||
# if the topic_id provided is different from the [quote topic:X].
|
||||
def self.markdown(text, opts = {})
|
||||
# we use the exact same markdown converter as the client
|
||||
# TODO: use the same extensions on both client and server (in particular the template for mentions)
|
||||
@@ -187,6 +189,9 @@ module PrettyText
|
||||
custom_emoji = {}
|
||||
Emoji.custom.map { |e| custom_emoji[e.name] = e.url }
|
||||
|
||||
# note, any additional options added to __optInput here must be
|
||||
# also be added to the buildOptions function in pretty-text.js,
|
||||
# otherwise they will be discarded
|
||||
buffer = +<<~JS
|
||||
__optInput = {};
|
||||
__optInput.siteSettings = #{SiteSetting.client_settings_json};
|
||||
@@ -216,6 +221,10 @@ module PrettyText
|
||||
buffer << "__optInput.topicId = #{opts[:topic_id].to_i};\n"
|
||||
end
|
||||
|
||||
if opts[:force_quote_link]
|
||||
buffer << "__optInput.forceQuoteLink = #{opts[:force_quote_link]};\n"
|
||||
end
|
||||
|
||||
if opts[:user_id]
|
||||
buffer << "__optInput.userId = #{opts[:user_id].to_i};\n"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user