Class: Brandish::Markup::Redcarpet::Format
- Inherits:
-
Object
- Object
- Brandish::Markup::Redcarpet::Format
- Defined in:
- lib/brandish/markup/redcarpet/format.rb
Overview
Formats text with Redcarpet. This is extracted into a seperate object in order to provide highlighting properties. This is format-independant.
This class can take the following options:
- All Markdown extension options that are listed on
https://github.com/vmg/redcarpet, e.g.
:no_intra_emphasis
,:tables
, etc. - All HTML formatter options that are listed on
https://github.com/vmg/redcarpet, e.g.
:filter_html
,:no_images
, etc. :highlight
- Optional. The highlighting engine to use. Can be one of:rouge
,:coderay
,:pygments
, and:none
. Remember to include the requisite highlighting engine in your Gemfile. They will automatically be required as needed. Defaults to:none
.
Constant Summary collapse
- MARKDOWN_OPTIONS =
The options that are passed over to the markdown engine. These are extracted from the options that are passed to the markup engine.
%i( no_intra_emphasis tables fenced_code_blocks autolink disable_indented_code_blocks strikethrough lax_spacing space_after_headers superscript underline quote footnotes ).freeze
- MARKDOWN_DEFAULTS =
The default options for the markdown engine as passed by this markup engine.
{ fenced_code_blocks: true, tables: true, autolink: true, strikethrough: true, superscript: true, underline: true, footnotes: true, space_after_headers: true }.freeze
- FORMAT_OPTIONS =
The options that are passed over to the formatting engine. These are Extracted from the options that are passed to the markup engine.
%i( filter_html no_images no_links no_styles escape_html safe_links_only with_toc_data hard_wrap xhtml prettify link_attributes highlight ).freeze
- FORMAT_DEFAULTS =
The default options for the formatting engine as passed by this markup engine.
{ highlight: :none }.freeze
- HIGHLIGHTERS =
The highlighting engines that are supported by this markup engine. The key is the value passed by the
:highlight
option, and the value is the require file name. If the value isnil
, no requirement is performed. { rouge: "rouge", coderay: "coderay", pygments: "pygments", none: nil }.freeze
- FORMATTERS =
The formating engines that can be used by this markup engine.
{ html: HTML }.freeze
Instance Method Summary collapse
-
#initialize(options) ⇒ Format
constructor
Initialize the markup engine for Redcarpet.
-
#render(string) ⇒ ::String
Renders the given text using the engine.
Constructor Details
#initialize(options) ⇒ Format
Initialize the markup engine for Redcarpet. For the available options, see Brandish::Markup::Redcarpet::Format.
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/brandish/markup/redcarpet/format.rb', line 79 def initialize() @context = .fetch(:context) @format = .fetch(:format) @markdown_options = MARKDOWN_DEFAULTS .merge((MARKDOWN_OPTIONS, )) @formatter_options = FORMAT_DEFAULTS .merge((FORMAT_OPTIONS, )) @highlight = @formatter_options[:highlight] load_highlighter load_engine end |
Instance Method Details
#render(string) ⇒ ::String
Renders the given text using the engine.
95 96 97 |
# File 'lib/brandish/markup/redcarpet/format.rb', line 95 def render(string) @engine.render(string) end |