Class: GeraBlog::RedcarpetCustom

Inherits:
Redcarpet::Render::HTML
  • Object
show all
Defined in:
lib/gerablog/redcarpet.rb

Overview

My subclass to perform parse with code bloques options

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#langObject (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{['&\"<>\/]},
    '&' => '&amp;',
    '<' => '&lt;',
    '>' => '&gt;',
    '"' => '&quot;',
    "'" => '&#x27;',
    '/' => '&#x2F;'
  )
end