2018-09-14 05:42:05 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-10-11 09:03:19 +00:00
|
|
|
module PreviewMarkdown
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
2017-11-22 07:50:36 +00:00
|
|
|
# rubocop:disable Gitlab/ModuleWithInstanceVariables
|
2017-10-11 09:03:19 +00:00
|
|
|
def preview_markdown
|
2019-10-29 12:06:40 +00:00
|
|
|
result = PreviewMarkdownService.new(@project, current_user, markdown_service_params).execute
|
2017-10-11 09:03:19 +00:00
|
|
|
|
|
|
|
render json: {
|
2019-11-14 03:06:25 +00:00
|
|
|
body: view_context.markdown(result[:text], markdown_context_params),
|
2017-10-11 09:03:19 +00:00
|
|
|
references: {
|
|
|
|
users: result[:users],
|
2019-04-04 13:08:34 +00:00
|
|
|
suggestions: SuggestionSerializer.new.represent_diff(result[:suggestions]),
|
2017-10-11 09:03:19 +00:00
|
|
|
commands: view_context.markdown(result[:commands])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
2018-12-13 19:17:19 +00:00
|
|
|
|
2019-10-29 12:06:40 +00:00
|
|
|
private
|
|
|
|
|
2018-12-13 19:17:19 +00:00
|
|
|
def projects_filter_params
|
|
|
|
{
|
2021-11-24 12:10:21 +00:00
|
|
|
issuable_reference_expansion_enabled: true,
|
2018-12-13 19:17:19 +00:00
|
|
|
suggestions_filter_enabled: params[:preview_suggestions].present?
|
|
|
|
}
|
|
|
|
end
|
2019-10-23 03:06:01 +00:00
|
|
|
|
2019-10-29 12:06:40 +00:00
|
|
|
def markdown_service_params
|
|
|
|
params
|
|
|
|
end
|
2019-11-14 03:06:25 +00:00
|
|
|
|
|
|
|
def markdown_context_params
|
|
|
|
case controller_name
|
2020-06-04 00:08:17 +00:00
|
|
|
when 'wikis' then { pipeline: :wiki, wiki: wiki, page_slug: params[:id] }
|
2019-11-14 03:06:25 +00:00
|
|
|
when 'snippets' then { skip_project_check: true }
|
|
|
|
when 'groups' then { group: group }
|
|
|
|
when 'projects' then projects_filter_params
|
|
|
|
else {}
|
2020-05-13 21:08:55 +00:00
|
|
|
end.merge(requested_path: params[:path], ref: params[:ref])
|
2019-11-14 03:06:25 +00:00
|
|
|
end
|
|
|
|
|
2019-10-31 21:06:28 +00:00
|
|
|
# rubocop:enable Gitlab/ModuleWithInstanceVariables
|
2017-10-11 09:03:19 +00:00
|
|
|
end
|