diff options
author | blackst0ne <blackst0ne.ru@gmail.com> | 2018-05-12 11:08:15 +1100 |
---|---|---|
committer | blackst0ne <blackst0ne.ru@gmail.com> | 2018-05-18 10:02:21 +1100 |
commit | 7e12e1aca3bae3c986aa7530915a785369d84e62 (patch) | |
tree | 7253d39f2824bee322344087bacee1cdc11a9073 | |
parent | d6c8a55189d62430c7ca4ffa6e5bb63f15a7efc1 (diff) | |
download | gitlab-ce-7e12e1aca3bae3c986aa7530915a785369d84e62.tar.gz |
Add API endpoint to render markdown text
-rw-r--r-- | lib/api/api.rb | 1 | ||||
-rw-r--r-- | lib/api/markdown.rb | 28 |
2 files changed, 29 insertions, 0 deletions
diff --git a/lib/api/api.rb b/lib/api/api.rb index 5139e869c71..136c142c377 100644 --- a/lib/api/api.rb +++ b/lib/api/api.rb @@ -139,6 +139,7 @@ module API mount ::API::Keys mount ::API::Labels mount ::API::Lint + mount ::API::Markdown mount ::API::Members mount ::API::MergeRequestDiffs mount ::API::MergeRequests diff --git a/lib/api/markdown.rb b/lib/api/markdown.rb new file mode 100644 index 00000000000..b5e4d88102e --- /dev/null +++ b/lib/api/markdown.rb @@ -0,0 +1,28 @@ +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" + all_or_none_of :gfm, :project + 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 } + + if params[:gfm] + context[:project] = Project.find_by_full_path(params[:project]) + else + context[:pipeline] = :plain_markdown + end + + present Banzai.render(params[:text], context) + end + end + end +end |