Class: GeraBlog::RedcarpetCustom
- Inherits:
-
Redcarpet::Render::HTML
- Object
- Redcarpet::Render::HTML
- GeraBlog::RedcarpetCustom
- Defined in:
- lib/gerablog/redcarpet.rb
Overview
My subclass to perform parse with code bloques options
Instance Attribute Summary collapse
-
#lang ⇒ Object
readonly
Returns the value of attribute lang.
Instance Method Summary collapse
- #block_code(code, language = nil) ⇒ Object
- #html_escape(string) ⇒ Object
-
#initialize(lang:) ⇒ RedcarpetCustom
constructor
A new instance of RedcarpetCustom.
Constructor Details
#initialize(lang:) ⇒ RedcarpetCustom
Returns a new instance of RedcarpetCustom.
8 9 10 11 |
# File 'lib/gerablog/redcarpet.rb', line 8 def initialize(lang:) super(prettify: true, escape_html: true) @lang = lang end |
Instance Attribute Details
#lang ⇒ Object (readonly)
Returns the value of attribute lang.
6 7 8 |
# File 'lib/gerablog/redcarpet.rb', line 6 def lang @lang end |
Instance Method Details
#block_code(code, language = nil) ⇒ Object
13 14 15 16 |
# File 'lib/gerablog/redcarpet.rb', line 13 def block_code(code, language = nil) l = language.nil? ? @lang : language %(<pre><code class="language-#{l}">\n#{html_escape(code)}\n</code></pre>) end |
#html_escape(string) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/gerablog/redcarpet.rb', line 18 def html_escape(string) string.gsub( %r{['&\"<>\/]}, '&' => '&', '<' => '<', '>' => '>', '"' => '"', "'" => ''', '/' => '/' ) end |