-
-
Notifications
You must be signed in to change notification settings - Fork 394
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #486 from akkee/472-markdown_API
Markdown API
- Loading branch information
Showing
4 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
class Gitlab::Client | ||
# Defines methods related to markdown. | ||
# @see https://docs.gitlab.com/ce/api/markdown.html | ||
module Markdown | ||
# Render an arbitrary Markdown document | ||
# | ||
# @example | ||
# Gitlab.markdown('Hello world! :tada:') | ||
# Gitlab.markdown('Hello world! :tada:', gfm: true, project: 'group_example/project_example') | ||
# | ||
# @param [String] text The markdown text to render. | ||
# @param [Hash] options A customizable set of options. | ||
# @option options [Boolean] :gfm(optional) Render text using GitLab Flavored Markdown. Default is false. | ||
# @option options [String] :project(optional) Use project as a context when creating references using GitLab Flavored Markdown. Authentication is required if a project is not public. | ||
# @return <Gitlab::ObjectifiedHash> Returns the rendered markdown as response | ||
def markdown(text, options = {}) | ||
body = { text: text }.merge(options) | ||
post('/markdown', body: body) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "html": "<p dir=\"auto\">Hello world! <gl-emoji title=\"party popper\" data-name=\"tada\" data-unicode-version=\"6.0\">🎉</gl-emoji></p>" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe Gitlab::Client do | ||
describe '.markdown' do | ||
before do | ||
stub_post('/markdown', 'markdown') | ||
Gitlab.markdown('Hello world! :tada:', gfm: true, project: 'group_example/project_example') | ||
end | ||
|
||
it 'gets the correct resource' do | ||
expect(a_post('/markdown') | ||
.with(body: { text: 'Hello world! :tada:', gfm: true, project: 'group_example/project_example' })).to have_been_made | ||
end | ||
end | ||
end |