Class: Klaro::Client::MdText

Inherits:
Object
  • Object
show all
Defined in:
lib/klaro/client/support/md_text.rb

Constant Summary collapse

SHARED_OPTIONS =
{
  unsafe: false,
}

Instance Method Summary collapse

Constructor Details

#initialize(src, variant) ⇒ MdText

Returns a new instance of MdText.



9
10
11
12
# File 'lib/klaro/client/support/md_text.rb', line 9

def initialize(src, variant)
  @src = src
  @variant = variant
end

Instance Method Details

#render_optionsObject



18
19
20
21
22
# File 'lib/klaro/client/support/md_text.rb', line 18

def render_options
  SHARED_OPTIONS.merge({
    hardbreaks: (@variant == :summary)
  })
end

#to_htmlObject



24
25
26
27
28
# File 'lib/klaro/client/support/md_text.rb', line 24

def to_html
  Commonmarker.to_html(to_s, options: {
    render: render_options
  }).strip.gsub(/<a href/, '<a target="_blank" href')
end

#to_sObject



14
15
16
# File 'lib/klaro/client/support/md_text.rb', line 14

def to_s
  @src
end