class GrapeSwagger::Markdown::RedcarpetAdapter
Attributes
Public Class Methods
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 {highlighter: :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
::new({highlighter: :none},{no_links: true}) # will use no syntax highlighter and won't render links.
# File lib/grape-swagger/markdown/redcarpet_adapter.rb, line 36 def initialize(options = {}) require 'redcarpet' extentions_defaults = { fenced_code_blocks: true, autolink: true } render_defaults = { highlighter: :rouge } @extension_options = extentions_defaults.merge(options.fetch(:extensions, {})) @render_options = render_defaults.merge(options.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
Public Instance Methods
Marks down the given text to html format.
# File lib/grape-swagger/markdown/redcarpet_adapter.rb, line 54 def markdown(text) @markdown.render(text) end
Private Instance Methods
Creates a new redcarpet renderer based on the highlighter given.
#render_options: options passed to the renderer.
usage: #new_redcarpet_renderer(:rouge) # uses rouge as highlighter. #new_redcarpet_renderer # no highlight plugin
# File lib/grape-swagger/markdown/redcarpet_adapter.rb, line 69 def new_redcarpet_renderer(syntax_highlighter = nil) case syntax_highlighter when :rouge begin Class.new(Redcarpet::Render::HTML) do require 'rouge' require 'rouge/plugins/redcarpet' include Rouge::Plugins::Redcarpet end rescue LoadError raise GrapeSwagger::Errors::MarkdownDependencyMissingError, 'rouge' end else Class.new(Redcarpet::Render::HTML) do include RenderWithoutSyntaxHighlighter end end end