Sha256: e603df893fbd7508f57c3505abf7319e357e3dc4f375e6acf2814dbb28c37e83
Contents?: true
Size: 1.15 KB
Versions: 5
Compression:
Stored size: 1.15 KB
Contents
# frozen_string_literal: false module Kitabu module Helpers def highlight_theme(name = theme) html = '<style type="text/css">' html << Rouge::Theme.find(name).render(scope: ".highlight") html << "</style>" html end def image_tag(path, _attributes = {}) %[<img src="images/#{path}" />] end def escape_html(content) CGI.escape_html(content.to_s) end def note(class_name = :info, &block) content = block_content(block) output << ('<div class="note %s">' % escape_html(class_name)) # rubocop:disable Style/FormatString output << markdown(content) output << "</div>" end def block_content(block) output = @_output.dup @_output = "" content = block.call @_output = output content end def markdown(content, deindent_content: true) content = deindent(content) if deindent_content Markdown.render(content) end def deindent(content) content = content.to_s indent = (content.scan(/^[ \t]*(?=\S)/) || []).size content.gsub(/^[ \t]{#{indent}}/, "") end def output @_output end end end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
kitabu-3.1.0 | lib/kitabu/helpers.rb |
kitabu-3.0.3 | lib/kitabu/helpers.rb |
kitabu-3.0.2 | lib/kitabu/helpers.rb |
kitabu-3.0.1 | lib/kitabu/helpers.rb |
kitabu-3.0.0 | lib/kitabu/helpers.rb |