Class: GrapeSwagger::Markdown::KramdownAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/grape-swagger/markdown/kramdown_adapter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ KramdownAdapter

Initializes the kramdown adapter with options. See kramdown documentation what options can be passed. Default it uses Github flavoured markup as input and won't use coderay as converter for syntax highlighting. config: an hash of configuration options to be passed to the kramdown. usage: Add the kramdown gem to your gemfile or run: $ (sudo) gem install kramdown

Then pass a new instance of GrapeSwagger::Markdown::KramdownAdapter as markdown option.



17
18
19
20
21
22
23
24
25
26
# File 'lib/grape-swagger/markdown/kramdown_adapter.rb', line 17

def initialize(config = {})
  require 'kramdown'
  defaults = {
    input: 'GFM',
    enable_coderay: false
  }
  @options = defaults.merge(config)
rescue LoadError
  raise GrapeSwagger::Errors::MarkdownDependencyMissingError, 'kramdown'
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options



4
5
6
# File 'lib/grape-swagger/markdown/kramdown_adapter.rb', line 4

def options
  @options
end

Instance Method Details

#markdown(text) ⇒ Object

marks down the given text to html format. text: The text to be formatted.



32
33
34
# File 'lib/grape-swagger/markdown/kramdown_adapter.rb', line 32

def markdown(text)
  Kramdown::Document.new(text, @options).to_html
end