Class: GrapeSwagger::Markdown::RedcarpetAdapter
- Inherits:
-
Object
- Object
- GrapeSwagger::Markdown::RedcarpetAdapter
- Defined in:
- lib/grape-swagger/markdown/redcarpet_adapter.rb
Defined Under Namespace
Modules: RenderWithoutSyntaxHighlighter
Instance Attribute Summary collapse
-
#extension_options ⇒ Object
readonly
Returns the value of attribute extension_options.
-
#render_options ⇒ Object
readonly
Returns the value of attribute render_options.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ RedcarpetAdapter
constructor
Initializes the redcarpet adapter with markup options.
-
#markdown(text) ⇒ Object
Marks down the given text to html format.
Constructor Details
#initialize(options = {}) ⇒ RedcarpetAdapter
Initializes the redcarpet adapter with markup options. See redcarpet documentation what options can be passed. Default it uses fenced_code_blocks, autolinks and rouge as syntax highlighter. To configure an highlighter add :value to the extentions hash. Currently supported highlighters:
:rouge
extensions: an hash of configuration options to be passed to markdown. render_options: an hash of configuration options to be passed to renderer.
usage: Add the redcarpet gem to your gemfile or run: $ (sudo) gem install redcarpet when you want to have rouge as syntax highlighter add rouge to the gemfile or run: $ (sudo) gem install rouge
GrapeSwagger::Markdown::RedcarpetAdapter.new(:none,true) # will use no syntax highlighter and won’t render links.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/grape-swagger/markdown/redcarpet_adapter.rb', line 36 def initialize( = {}) require 'redcarpet' extentions_defaults = { fenced_code_blocks: true, autolink: true } render_defaults = { highlighter: :rouge } @extension_options = extentions_defaults.merge(.fetch(:extensions, {})) @render_options = render_defaults.merge(.fetch(:render_options, {})) @renderer = new_redcarpet_renderer(@render_options.delete(:highlighter)).new(@render_options) @markdown = Redcarpet::Markdown.new(@renderer, @extension_options) rescue LoadError raise GrapeSwagger::Errors::MarkdownDependencyMissingError, 'redcarpet' end |
Instance Attribute Details
#extension_options ⇒ Object (readonly)
Returns the value of attribute extension_options.
13 14 15 |
# File 'lib/grape-swagger/markdown/redcarpet_adapter.rb', line 13 def @extension_options end |
#render_options ⇒ Object (readonly)
Returns the value of attribute render_options.
15 16 17 |
# File 'lib/grape-swagger/markdown/redcarpet_adapter.rb', line 15 def @render_options end |
Instance Method Details
#markdown(text) ⇒ Object
Marks down the given text to html format.
54 55 56 |
# File 'lib/grape-swagger/markdown/redcarpet_adapter.rb', line 54 def markdown(text) @markdown.render(text) end |