2018-09-29 18:34:47 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-05-18 06:25:59 -04:00
|
|
|
module API
|
2020-10-14 20:08:42 -04:00
|
|
|
class Markdown < ::API::Base
|
2022-08-11 08:09:19 -04:00
|
|
|
before { authenticate! if Feature.enabled?(:authenticate_markdown_api, type: :ops) }
|
|
|
|
|
|
|
|
feature_category :team_planning
|
2020-10-29 14:09:11 -04:00
|
|
|
|
2018-05-18 06:25:59 -04:00
|
|
|
params do
|
|
|
|
requires :text, type: String, desc: "The markdown text to render"
|
|
|
|
optional :gfm, type: Boolean, desc: "Render text using GitLab Flavored Markdown"
|
|
|
|
optional :project, type: String, desc: "The full path of a project to use as the context when creating references using GitLab Flavored Markdown"
|
|
|
|
end
|
|
|
|
resource :markdown do
|
|
|
|
desc "Render markdown text" do
|
|
|
|
detail "This feature was introduced in GitLab 11.0."
|
|
|
|
end
|
|
|
|
post do
|
2018-09-19 15:58:43 -04:00
|
|
|
context = { only_path: false, current_user: current_user }
|
|
|
|
context[:pipeline] = params[:gfm] ? :full : :plain_markdown
|
2018-05-18 06:25:59 -04:00
|
|
|
|
|
|
|
if params[:project]
|
|
|
|
project = Project.find_by_full_path(params[:project])
|
|
|
|
|
|
|
|
not_found!("Project") unless can?(current_user, :read_project, project)
|
|
|
|
|
|
|
|
context[:project] = project
|
|
|
|
else
|
|
|
|
context[:skip_project_check] = true
|
|
|
|
end
|
|
|
|
|
2018-09-19 15:58:43 -04:00
|
|
|
{ html: Banzai.render_and_post_process(params[:text], context) }
|
2018-05-18 06:25:59 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|