Class: Brandish::Markup::Redcarpet::HTML
- Inherits:
-
Redcarpet::Render::SmartyHTML
- Object
- Redcarpet::Render::SmartyHTML
- Brandish::Markup::Redcarpet::HTML
- Includes:
- Hanami::Helpers::EscapeHelper, Hanami::Helpers::HtmlHelper
- Defined in:
- lib/brandish/markup/redcarpet/html.rb
Overview
An HTML renderer for redcarpet. This provides integrations with Brandish, as well as code highlighting.
Constant Summary collapse
- TAGS =
The tags for each level of header.
%i(h1 h2 h3 h4 h5 h6).freeze
Instance Method Summary collapse
-
#block_code(code, language) ⇒ ::String
Highlights a block of code.
-
#header(text, level) ⇒ ::String
Creates a header with the given text and level.
-
#initialize(context, options) ⇒ HTML
constructor
Initialize the renderer with the given context and options.
Constructor Details
#initialize(context, options) ⇒ HTML
Initialize the renderer with the given context and options.
28 29 30 31 32 |
# File 'lib/brandish/markup/redcarpet/html.rb', line 28 def initialize(context, ) @context = context @highlighter = .fetch(:highlight) super() end |
Instance Method Details
#block_code(code, language) ⇒ ::String
Highlights a block of code.
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/brandish/markup/redcarpet/html.rb', line 53 def block_code(code, language) basic_language = language || "unknown" case @highlighter when :rouge then rouge_highlight_code(code, language) when :coderay then coderay_highlight_code(code, language) when :pygments then pygments_highlight_code(code, language) when :none html.pre { html.code(code, class: "language-#{basic_language}") } end.to_s end |
#header(text, level) ⇒ ::String
Creates a header with the given text and level. If the text ends in
/#([\w-]+)/
, that is removed, and used as the ID for the header;
otherwise, it is automagically assumed from the text.
41 42 43 44 45 |
# File 'lib/brandish/markup/redcarpet/html.rb', line 41 def header(text, level) text, id = split_text(text) html.tag(TAGS.fetch(level), raw(text), id: id).to_s end |