· 1 min read

Screencast: Markdown mit Redcarpet

Downloads in verschiedenen Formaten:

source code mp4 m4v webm ogv

Resourcen:

bash

[bash] sudo easy_install pygments [/bash]

Gemfile

[ruby] gem ‘redcarpet’ gem ‘albino’ gem ‘nokogiri’ [/ruby]

application_helper.rb

[ruby] def markdown(text) options = [:hard_wrap, :filter_html, :autolink, :no_intraemphasis, :fenced_code, :gh_blockcode] syntax_highlighter(Redcarpet.new(text, *options).to_html).html_safe end

def syntax_highlighter(html) doc = Nokogiri::HTML(html) doc.search(“//pre[@lang]“).each do |pre| pre.replace Albino.colorize(pre.text.rstrip, pre[:lang]) end doc.to_s end [/ruby]

articles/show.html.erb

[html] <%= markdown(@article.content) %> [/html]

Back to Blog