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, options = {}) ⇒ MdText

Returns a new instance of MdText.



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

def initialize(src, variant, options = {})
  @src = src
  @variant = variant
  @options = SHARED_OPTIONS.merge(options)
end

Instance Method Details

#render_optionsObject



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

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

#to_html(options = {}) ⇒ Object



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

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

#to_sObject



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

def to_s
  @src
end