formol-markdown 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ nbproject
2
+ *.gem
data/LICENSE ADDED
@@ -0,0 +1,3 @@
1
+ == formol-markdown
2
+
3
+ Put appropriate LICENSE for your project here.
data/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # Markdown text processor for Formol forum engine
2
+
3
+ Just add this gem in your Gemfile, after formol's.
4
+
5
+ ```ruby
6
+ gem 'formol'
7
+ gem 'formol-markdown'
8
+ ```
9
+
10
+ It adds `Formol::Formatters::Redcarpet::Formatter` to Formol.formatters.
11
+
12
+ You need then to add in your formol initializer:
13
+ `config.text_formatter = :markdown`
14
+
15
+ It supports syntax highlighting and quotes. Have fun!
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ #
2
+ # To change this template, choose Tools | Templates
3
+ # and open the template in the editor.
4
+
5
+
6
+ require 'rubygems'
7
+ require 'rake'
8
+ require 'rake/clean'
9
+ require 'rake/gempackagetask'
10
+ require 'rake/rdoctask'
11
+ require 'rake/testtask'
12
+ require 'spec/rake/spectask'
13
+
14
+ spec = Gem::Specification.new do |s|
15
+ s.name = 'formol-markdown'
16
+ s.version = '0.0.1'
17
+ s.has_rdoc = true
18
+ s.extra_rdoc_files = ['README', 'LICENSE']
19
+ s.summary = 'Your summary here'
20
+ s.description = s.summary
21
+ s.author = ''
22
+ s.email = ''
23
+ # s.executables = ['your_executable_here']
24
+ s.files = %w(LICENSE README Rakefile) + Dir.glob("{bin,lib,spec}/**/*")
25
+ s.require_path = "lib"
26
+ s.bindir = "bin"
27
+ end
28
+
29
+ Rake::GemPackageTask.new(spec) do |p|
30
+ p.gem_spec = spec
31
+ p.need_tar = true
32
+ p.need_zip = true
33
+ end
34
+
35
+ Rake::RDocTask.new do |rdoc|
36
+ files =['README', 'LICENSE', 'lib/**/*.rb']
37
+ rdoc.rdoc_files.add(files)
38
+ rdoc.main = "README" # page to start on
39
+ rdoc.title = "formol-markdown Docs"
40
+ rdoc.rdoc_dir = 'doc/rdoc' # rdoc output folder
41
+ rdoc.options << '--line-numbers'
42
+ end
43
+
44
+ Rake::TestTask.new do |t|
45
+ t.test_files = FileList['test/**/*.rb']
46
+ end
47
+
48
+ Spec::Rake::SpecTask.new do |t|
49
+ t.spec_files = FileList['spec/**/*.rb']
50
+ t.libs << Dir["lib"]
51
+ end
@@ -0,0 +1,18 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ # Describe your gem and declare its dependencies:
4
+ Gem::Specification.new do |s|
5
+ s.name = "formol-markdown"
6
+ s.version = "1.0.0"
7
+ s.authors = ["Florian DUTEY"]
8
+ s.email = ["fdutey@gmail.com"]
9
+ s.homepage = "https://github.com/mulasse/formol-markdown"
10
+ s.summary = "Markdown formatter for formol forum engine"
11
+ s.description = "Markdown formatter for formol forum engine"
12
+
13
+ s.files = `git ls-files`.split("\n")
14
+ s.require_paths = ["lib"]
15
+
16
+ s.add_dependency 'pygments.rb'
17
+ s.add_dependency 'redcarpet'
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'redcarpet'
2
+ require 'pygments.rb'
3
+
4
+ require 'formol/formatters/redcarpet/formatter.rb'
5
+ require 'formol/formatters/redcarpet/syntax_highlighter'
6
+
7
+ Formol.formatters[:markdown] = Formol::Formatters::Redcarpet::Formatter
@@ -0,0 +1,43 @@
1
+ module Formol
2
+ module Formatters
3
+ module Redcarpet
4
+ class Formatter
5
+ def initialize
6
+ @renderer = SyntaxHighlighter.new(:hard_wrap => true,
7
+ :filter_html => true)
8
+ @processor = ::Redcarpet::Markdown.new(@renderer, :fenced_code_blocks => true,
9
+ :no_intra_emphasis => true,
10
+ :autolink => true,
11
+ :space_after_headers => false,
12
+ :superscript => false)
13
+ end
14
+
15
+ def to_html(text)
16
+ @processor.render(text).html_safe
17
+ end
18
+
19
+ def quote(author_name, text)
20
+ wrote = I18n.t('formol.posts.wrote')
21
+
22
+ text_with_author = "**#{author_name} #{wrote}:**\n\n"
23
+ text_with_author << text
24
+
25
+ blockquote(text_with_author)
26
+ end
27
+
28
+ def blockquote(text)
29
+ quoted_text = ""
30
+
31
+ # this is needed to highlight work in quotes
32
+ text.split("\n").each_with_index do |line, index|
33
+ quoted_text << '> ' if index == 0 || (line.strip.blank? || line.start_with?('>'))
34
+ quoted_text << line
35
+ quoted_text << "\n"
36
+ end
37
+
38
+ quoted_text
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,20 @@
1
+ module Formol
2
+ module Formatters
3
+ module Redcarpet
4
+ class SyntaxHighlighter < ::Redcarpet::Render::XHTML
5
+ def block_code(code, language)
6
+ title_block(language) + Pygments.highlight(code, :lexer => language,
7
+ :options => {
8
+ :linenos => 'inline'
9
+ })
10
+ end
11
+
12
+ private
13
+
14
+ def title_block(language)
15
+ %{<div class="highlight_title #{language.downcase}">#{language.downcase.capitalize}</div>}
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: formol-markdown
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Florian DUTEY
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-17 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: pygments.rb
16
+ requirement: &75542450 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *75542450
25
+ - !ruby/object:Gem::Dependency
26
+ name: redcarpet
27
+ requirement: &75542030 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *75542030
36
+ description: Markdown formatter for formol forum engine
37
+ email:
38
+ - fdutey@gmail.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - LICENSE
45
+ - README.md
46
+ - Rakefile
47
+ - formol-markdown.gemspec
48
+ - lib/formol-markdown.rb
49
+ - lib/formol/formatters/redcarpet/formatter.rb
50
+ - lib/formol/formatters/redcarpet/syntax_highlighter.rb
51
+ homepage: https://github.com/mulasse/formol-markdown
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: Markdown formatter for formol forum engine
75
+ test_files: []