@@ -43,31 +43,36 @@ module TextFormatting
4343
4444 # @!macro format_text_params
4545 # @param [Project] project a Project context.
46- # @param [Boolean] only_path whether to generate links with relative URLs.
46+ # @param [Symbol] render_mode the rendering channel (`:in_app_html`,
47+ # `:external_html`, `:external_text`). Resolves the `only_path`,
48+ # `static_html` and `plain_text` context flags as a set. Prefer this
49+ # over passing the primitives individually. See {RenderMode}.
50+ # @param [Boolean] only_path explicit override for the resolved `only_path`.
4751 # @param [User] current_user the current user context.
4852 # @param [:plain, :rich] format the text format.
4953 # `:plain` will return plain text.
5054 # `:rich` will render raw Markdown as HTML.
5155 # @param ** [Hash] additional context to pass to the underlying rendering
52- # pipeline.
56+ # pipeline. Explicit `static_html:` / `plain_text:` here override the
57+ # values resolved from `render_mode:`.
5358
5459 # rubocop:disable Layout/LineLength
5560
5661 ##
5762 # Formats text according to system settings and provided params.
5863 #
59- # @overload format_text(text, object: nil, project: @project || object.try(:project), only_path: true , current_user: User.current, format: :rich, **)
64+ # @overload format_text(text, object: nil, project: @project || object.try(:project), render_mode: :in_app_html, only_path: nil , current_user: User.current, format: :rich, **)
6065 #
6166 # @param [String] text the raw text to be formatted, typically Markdown.
6267 # @param [Object] object an object context.
6368 # @macro format_text_params
6469 #
6570 # @example Setting a project context explicitly
6671 # format_text("## Hello world", project: current_project)
67- # @example Generating links with full URLs
68- # format_text("[Projects](/projects) ", only_path: false )
72+ # @example Rendering for an external surface (mailer, RSS, export)
73+ # format_text("see #42 ", render_mode: :external_html )
6974 #
70- # @overload format_text(object, attribute, project: @project || object.try(:project), only_path: true , current_user: User.current, format: :rich, **)
75+ # @overload format_text(object, attribute, project: @project || object.try(:project), render_mode: :in_app_html, only_path: nil , current_user: User.current, format: :rich, **)
7176 #
7277 # @param [Object] object an object, typically a model
7378 # (i.e. `ActiveRecord::Base` descendent).
@@ -79,7 +84,8 @@ module TextFormatting
7984 # format_text(issue, :description, options)
8085 #
8186 # @return [String] the formatted text as an HTML-safe String.
82- def format_text ( *args , object : nil , project : nil , only_path : true , current_user : User . current , format : :rich , **)
87+ def format_text ( *args , object : nil , project : nil , render_mode : :in_app_html ,
88+ only_path : nil , current_user : User . current , format : :rich , **kwargs )
8389 case args . size
8490 when 1
8591 attribute = nil
@@ -94,15 +100,22 @@ def format_text(*args, object: nil, project: nil, only_path: true, current_user:
94100
95101 project ||= @project || object . try ( :project )
96102
103+ resolved = RenderMode . resolve (
104+ render_mode ,
105+ only_path :,
106+ static_html : kwargs . delete ( :static_html ) ,
107+ plain_text : kwargs . delete ( :plain_text )
108+ )
109+
97110 Renderer . format_text (
98111 text ,
99- **,
112+ **kwargs ,
100113 format :,
101114 object :,
102115 request : try ( :request ) ,
103116 current_user :,
104117 attribute :,
105- only_path : ,
118+ ** resolved ,
106119 project :
107120 )
108121 end
0 commit comments