diff options
author | blackst0ne <blackst0ne.ru@gmail.com> | 2018-05-18 10:25:59 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2018-05-18 10:25:59 +0000 |
commit | c0e77f7c9cc24104981bb8f6973ceeb9c311e1e2 (patch) | |
tree | 54402d82ae262b212613408c011477e664ace0d3 /lib/api/markdown.rb | |
parent | 9f863dbe1a5ed324b7fb202eea11397d1fcdd61f (diff) | |
download | gitlab-ce-c0e77f7c9cc24104981bb8f6973ceeb9c311e1e2.tar.gz |
Resolve "Expand API: Render an arbitrary Markdown document"
Diffstat (limited to 'lib/api/markdown.rb')
-rw-r--r-- | lib/api/markdown.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/api/markdown.rb b/lib/api/markdown.rb new file mode 100644 index 00000000000..b9ed68aa584 --- /dev/null +++ b/lib/api/markdown.rb @@ -0,0 +1,33 @@ +module API + class Markdown < Grape::API + 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 + # Explicitly set CommonMark as markdown engine to use. + # Remove this set when https://gitlab.com/gitlab-org/gitlab-ce/issues/43011 is done. + context = { markdown_engine: :common_mark, only_path: false } + + 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 + + context[:pipeline] = params[:gfm] ? :full : :plain_markdown + + { html: Banzai.render(params[:text], context) } + end + end + end +end |