Module: CrudComponents::Markup

Defined in:
lib/crud_components/markup.rb

Overview

Soft-dependency markup rendering: works with whichever gem the host app already has; raises at structure build (not here) when none is present.

Class Method Summary collapse

Class Method Details

.asciidoc(source) ⇒ Object



23
24
25
26
27
# File 'lib/crud_components/markup.rb', line 23

def asciidoc(source)
  return source.to_s unless defined?(Asciidoctor)

  Asciidoctor.convert(source.to_s, safe: :safe)
end

.highlight_json(pretty) ⇒ Object



29
30
31
32
33
34
# File 'lib/crud_components/markup.rb', line 29

def highlight_json(pretty)
  return nil unless defined?(Rouge)

  formatter = Rouge::Formatters::HTMLInline.new(Rouge::Themes::Github.new)
  formatter.format(Rouge::Lexers::JSON.new.lex(pretty))
end

.markdown(source) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/crud_components/markup.rb', line 7

def markdown(source)
  source = source.to_s
  if defined?(Commonmarker)
    Commonmarker.to_html(source)
  elsif defined?(CommonMarker)
    CommonMarker.render_html(source)
  elsif defined?(Redcarpet)
    @redcarpet ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML.new)
    @redcarpet.render(source)
  elsif defined?(Kramdown)
    Kramdown::Document.new(source).to_html
  else
    source
  end
end