Class: CS50::SpoilerBlock

Inherits:
Liquid::Block
  • Object
show all
Defined in:
lib/jekyll-theme-cs50.rb

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, text, tokens) ⇒ SpoilerBlock

Returns a new instance of SpoilerBlock.


55
56
57
58
# File 'lib/jekyll-theme-cs50.rb', line 55

def initialize(tag_name, text, tokens)
  super
  @text = (text.length > 0) ? CGI.escapeHTML(text.strip().gsub(/\A"|"\Z/, "").gsub(/\A"|"\Z/, "")) : "Spoiler"
end

Instance Method Details

#render(context) ⇒ Object


62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/jekyll-theme-cs50.rb', line 62

def render(context)
  site = context.registers[:site]
  converter = site.find_converter_instance(::Jekyll::Converters::Markdown)
  summary = Sanitize.fragment(converter.convert(@text), :elements => ["b", "code", "em", "i", "img", "span", "strong", "sub", "sup"])
  details = converter.convert(super(context))
  <<~EOT
    <details>
        <summary>#{summary}</summary>
        #{details}
    </details>
  EOT
end