Class | Nanoc::Filters::ColorizeSyntax |
In: |
lib/nanoc/filters/colorize_syntax.rb
|
Parent: | Nanoc::Filter |
DEFAULT_COLORIZER | = | :coderay | The default colorizer to use for a language if the colorizer for that language is not overridden. | |
SIMON_HIGHLIGHT_OPT_MAP | = | { :wrap => '-W', :include_style => '-I', :line_numbers => '-l', } | ||
KNOWN_COLORIZERS | = | [ :coderay, :dummy, :pygmentize, :pygmentsrb, :simon_highlight ] |
Runs the content through [pygmentize](pygments.org/docs/cmdline/), the commandline frontend for [Pygments](pygments.org/).
@api private
@param [String] code The code to colorize
@param [String] language The language the code is written in
@option params [String, Symbol] :encoding The encoding of the code block
@return [String] The colorized output
Runs the content through [Pygments](pygments.org/) via [pygments.rb](github.com/tmm1/pygments.rb).
@api private
@param [String] code The code to colorize
@param [String] language The language the code is written in
@return [String] The colorized output
Syntax-highlights code blocks in the given content. Code blocks should be enclosed in `pre` elements that contain a `code` element. The code element should have an indication of the language the code is in. There are two possible ways of adding such an indication:
code language, as specified by HTML5. For example, `<code class="language-ruby">`.
`#!language` where `language` is the language the code is in. For example, `#!ruby`.
Options for individual colorizers will be taken from the {run} options’ value for the given colorizer. For example, if the filter is invoked with a `:coderay => coderay_options_hash` option, the `coderay_options_hash` hash will be passed to the CodeRay colorizer.
Currently, the following colorizers are supported:
Additional colorizer implementations are welcome!
@example Using a class to indicate type of code be highlighted
<pre><code class="language-ruby"> def foo "asdf" end </code></pre>
@example Using a comment to indicate type of code be highlighted
<pre><code> #!ruby def foo "asdf" end </code></pre>
@example Invoking the filter with custom parameters
filter :colorize_syntax, :colorizers => { :ruby => :coderay }, :coderay => { :line_numbers => :list }
@param [String] content The content to filter
@option params [Symbol] :default_colorizer (DEFAULT_COLORIZER) The
default colorizer, i.e. the colorizer that will be used when the colorizer is not overriden for a specific language.
@option params [Symbol] :syntax (:html) The syntax to use, which can be
`:html`, `:xml` or `:xhtml`, the latter two being the same.
@option params [Hash] :colorizers ({}) A hash containing
a mapping of programming languages (symbols, not strings) onto colorizers (symbols).
@option params [Boolean] :outside_pre (false) `true` if the colorizer
should be applied on `code` elements outside `pre` elements, false if only `code` elements inside` pre` elements should be colorized.
@option params [Symbol] :is_fullpage (false) Whether to treat the input
as a full HTML page or a page fragment. When true, HTML boilerplate such as the doctype, `html`, `head` and `body` elements will be added.
@return [String] The filtered content
Runs the content through [Highlight](www.andre-simon.de/doku/highlight/en/highlight.html).
@api private
@since 3.2.0
@param [String] code The code to colorize
@param [String] language The language the code is written in
@option params [String] :style The style to use
@return [String] The colorized output