Class: Markdownplus::Bootstrap2Renderer

Inherits:
Redcarpet::Render::HTML
  • Object
show all
Defined in:
lib/markdownplus/parser.rb

Overview

def initialize(opts={})

  @name = opts[:name]
  @params = opts[:params]
end

end

Instance Method Summary collapse

Instance Method Details

#block_code(code, language) ⇒ Object

alias_method :existing_block_code, :block_code



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/markdownplus/parser.rb', line 220

def block_code(code, language)
  if language == "csv"
    result = "<table class='table table-striped'>"
    row_num = 0
    CSV.parse(code) do |row|
      if row_num == 0
        result += "<thead><tr>#{row.collect { |c| "<th>#{c}</th>"}.join}</tr></thead>\n<tbody>\n"
      else
        result += "<tr>#{row.collect { |c| "<td>#{c}</td>"}.join}</tr>\n"
      end
      row_num += 1
    end
    result += "</tbody></table>"
  elsif language == "formatted_json"
    begin
      obj = JSON.parse(code)
      result = Pygments.highlight(JSON.pretty_generate(obj), lexer: "json")
    rescue => e
      result = Pygments.highlight(code, lexer: "json")
    end
  else
    result = Pygments.highlight(code, lexer: language)
  end
  result
end