module ApplicationHelper

  def organization_options
    current_user.organizations.collect { |o|
      [
        o.organization.login,
        o.organization.login,
        { 'data-content' => "<img src='#{o.organization.avatar_url}' height='20' width='20' /> #{o.organization.login}" }
      ]
    }
  end

  def user_option
    [
      current_user.github_username,
      nil,
      { 'data-content' => "<img src='#{current_user.github_user.avatar_url}' height='20' width='20' /> #{current_user.github_username}" }
    ]
  end

  def organization_select_options
    organization_options.unshift(user_option)
  end

  class CodeRayify < Redcarpet::Render::HTML
    def block_code(code, language)
        CodeRay.scan(code, language).div
    end
  end

  def markdown(text)
      coderayified = CodeRayify.new(filter_html: true,  hard_wrap: true)
      options = {
          fenced_code_blocks: true,
          no_intra_emphasis: true,
          autolink: true,
          strikethrough: true,
          lax_html_blocks: true,
          superscript: true
      }
      markdown_to_html = Redcarpet::Markdown.new(coderayified, options)
      markdown_to_html.render(text).html_safe
  end

  def markdown_json(json_text)
    markdown("```json\n#{json_text}```")
  end

end

module ApplicationHelper

  def organization_options
    current_user.organizations.collect { |o|
      [
        o.organization.login,
        o.organization.login,
        { 'data-content' => "<img src='#{o.organization.avatar_url}' height='20' width='20' /> #{o.organization.login}" }
      ]
    }
  end

  def user_option
    [
      current_user.github_username,
      nil,
      { 'data-content' => "<img src='#{current_user.github_user.avatar_url}' height='20' width='20' /> #{current_user.github_username}" }
    ]
  end

  def organization_select_options
    organization_options.unshift(user_option)
  end

  class CodeRayify < Redcarpet::Render::HTML
    def block_code(code, language)
        CodeRay.scan(code, language).div
    end
  end

  def markdown(text)
      coderayified = CodeRayify.new(filter_html: true,  hard_wrap: true)
      options = {
          fenced_code_blocks: true,
          no_intra_emphasis: true,
          autolink: true,
          strikethrough: true,
          lax_html_blocks: true,
          superscript: true
      }
      markdown_to_html = Redcarpet::Markdown.new(coderayified, options)
      markdown_to_html.render(text).html_safe
  end

  def markdown_json(json_text)
    pretty_json = JSON.pretty_generate JSON.parse(json_text)
    markdown("```json\n#{pretty_json}")
  end

end

Update so that json is 'pretty' printed too
Update so that json is 'pretty' printed too

For some reason, the tailing code markdown code was being rendered
so it has been removed. Not sure what was happening.
