forem-redcarpet 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in forem-rdiscount.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # Forem + Redcarpet = :heart:
2
+
3
+ Simply specify this gem as a dependency of your application that also contains Forem:
4
+
5
+ gem 'forem', :git => "git://github.com/radar/forem"
6
+ gem 'forem-redcarpet', :git => "git://github.com/radar/forem-redcarpet"
7
+
8
+ The code will do the rest!
9
+
10
+ Comes with syntax highlighting provided by Redcarpet, however you'll need to generate the CSS yourself with this lovely command:
11
+
12
+ Pygments.css
13
+
14
+ Enjoy!
15
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "forem-redcarpet"
6
+ s.version = "1.0.0"
7
+ s.authors = ["Ryan Bigg"]
8
+ s.email = ["radarlistener@gmail.com"]
9
+ s.homepage = ""
10
+ s.summary = %q{Provides Redcarpet markup (with syntax highlighting by pygments.rb) for Forem posts}
11
+ s.description = %q{Provides Recarpet markup (with syntax highlighting by pygments.rb) for Forem posts}
12
+
13
+ s.files = `git ls-files`.split("\n")
14
+ s.require_paths = ["lib"]
15
+
16
+ s.add_dependency 'redcarpet', '2.0.1'
17
+ s.add_dependency 'pygments.rb', '0.2.4'
18
+ end
@@ -0,0 +1,3 @@
1
+ require "forem/formatters/redcarpet"
2
+
3
+ Forem.formatter = Forem::Formatters::Redcarpet
@@ -0,0 +1,28 @@
1
+ require 'redcarpet'
2
+ require 'pygments'
3
+
4
+ module Forem
5
+ module Formatters
6
+ class Redcarpet
7
+ def self.format(text)
8
+ options = [:hard_wrap, :filter_html, :autolink, :no_intraemphasis, :fenced_code, :gh_blockcode]
9
+ renderer = ::Redcarpet::Markdown.new(::Redcarpet::Render::HTML, :fenced_code_blocks => true)
10
+ syntax_highlight(renderer.render(text)).html_safe
11
+ end
12
+
13
+ def self.blockquote(text)
14
+ text.split("\n").map do |line|
15
+ "> " + line
16
+ end.join("\n")
17
+ end
18
+
19
+ def self.syntax_highlight(html)
20
+ doc = Nokogiri::HTML::DocumentFragment.parse(html.to_s)
21
+ doc.css("pre code[@class]").each do |code|
22
+ code.replace Pygments.highlight(code.text.rstrip, :lexer => code[:class], :class => "forem_highlight")
23
+ end
24
+ doc.to_s
25
+ end
26
+ end
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: forem-redcarpet
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ryan Bigg
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: redcarpet
16
+ requirement: &70248242984720 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - =
20
+ - !ruby/object:Gem::Version
21
+ version: 2.0.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70248242984720
25
+ - !ruby/object:Gem::Dependency
26
+ name: pygments.rb
27
+ requirement: &70248242965800 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - =
31
+ - !ruby/object:Gem::Version
32
+ version: 0.2.4
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70248242965800
36
+ description: Provides Recarpet markup (with syntax highlighting by pygments.rb) for
37
+ Forem posts
38
+ email:
39
+ - radarlistener@gmail.com
40
+ executables: []
41
+ extensions: []
42
+ extra_rdoc_files: []
43
+ files:
44
+ - .gitignore
45
+ - Gemfile
46
+ - README.md
47
+ - Rakefile
48
+ - forem-redcarpet.gemspec
49
+ - lib/forem-redcarpet.rb
50
+ - lib/forem/formatters/redcarpet.rb
51
+ homepage: ''
52
+ licenses: []
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 1.8.10
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Provides Redcarpet markup (with syntax highlighting by pygments.rb) for Forem
75
+ posts
76
+ test_files: []