k33l0r-redclothcoderay 0.3.4 → 0.3.5
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/MIT-LICENSE +20 -0
- data/README.rdoc +58 -0
- data/Rakefile +23 -0
- data/lib/redclothcoderay.rb +38 -0
- data/redclothcoderay.gemspec +16 -0
- data/test/coderay_options_test.rb +18 -0
- data/test/redclothcoderay_test.rb +74 -0
- data/test/test_helper.rb +7 -0
- metadata +14 -5
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 August Lilleaas
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
== Redcloth with CodeRay
|
2
|
+
|
3
|
+
Adds CodeRay syntax highlighting support to RedCloth, with a 'source' tag. See the examples below.
|
4
|
+
|
5
|
+
A short summary of what you can do:
|
6
|
+
|
7
|
+
* <source>foo</source> - Use this tag to produce CodeRay highlighted HTML for the contents within that tag. The language defaults to Ruby.
|
8
|
+
* <source:css>foo</source> - Highlight as usual, but highlight as CSS. Supports everything CodeRay supports. Refer to the CodeRay documentation for a list of supported languages.
|
9
|
+
* You can also use the <code> tag.
|
10
|
+
|
11
|
+
== Installing
|
12
|
+
|
13
|
+
Installation as usual:
|
14
|
+
|
15
|
+
sudo gem install redclothcoderay
|
16
|
+
|
17
|
+
You can also install the gem via github, to get the latest HEAD.
|
18
|
+
|
19
|
+
sudo gem install augustl-redclothcoderay --source=http://gems.github.com/
|
20
|
+
|
21
|
+
== Using
|
22
|
+
|
23
|
+
A short example.
|
24
|
+
|
25
|
+
require 'rubygems'
|
26
|
+
require 'redcloth'
|
27
|
+
require 'coderay'
|
28
|
+
require 'redclothcoderay'
|
29
|
+
|
30
|
+
RedCloth.new('I am *bold* and <source>@hi_tech</source>').to_html
|
31
|
+
|
32
|
+
You can specify the CodeRay options, too (defaults to RedclothCoderay::CODERAY_OPTIONS).
|
33
|
+
|
34
|
+
RedclothCoderay.coderay_options :line_numbers => :table
|
35
|
+
|
36
|
+
== Example
|
37
|
+
|
38
|
+
This input:
|
39
|
+
|
40
|
+
Hello, this is *textilized*. It also has <source>@inline_code_examples</source>!
|
41
|
+
|
42
|
+
What about a multi-line code sample?
|
43
|
+
|
44
|
+
<source:html>
|
45
|
+
<h1>Hello, world!</h1>
|
46
|
+
</source>
|
47
|
+
|
48
|
+
produces this output (indented for clarity):
|
49
|
+
|
50
|
+
<p>Hello, this is <strong>textilized</strong>. It also has <code class="inline_code">
|
51
|
+
<span class="iv">@inline_code_examples</span>
|
52
|
+
</code>!</p>
|
53
|
+
|
54
|
+
<p>What about a multi-line code sample?</p>
|
55
|
+
|
56
|
+
<pre><code class=\"multiline_code\">
|
57
|
+
<span class=\"ta\">&lt;h1&gt;</span>Hello, world!<span class=\"ta\">&lt;/h1&gt;</span>
|
58
|
+
</code></pre>
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__), 'test')
|
4
|
+
|
5
|
+
task :default => "test:v4"
|
6
|
+
|
7
|
+
namespace :test do
|
8
|
+
desc "Test RedCloth 3"
|
9
|
+
task :v3 do
|
10
|
+
gem 'RedCloth', "< 4.0.0"
|
11
|
+
require 'RedCloth'
|
12
|
+
|
13
|
+
load "test/redclothcoderay_test.rb"
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "Test RedCloth 4"
|
17
|
+
task :v4 do
|
18
|
+
gem 'RedCloth', ">= 4.0.0"
|
19
|
+
require 'RedCloth'
|
20
|
+
|
21
|
+
load "test/redclothcoderay_test.rb"
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module RedclothCoderay
|
2
|
+
SINGLE_LINE = '<code class="inline_code">%s</code>'
|
3
|
+
MULTI_LINE = '<div class="multiline_code">%s</div>'
|
4
|
+
SOURCE_TAG_REGEXP = /(([\t\n])?<source(?:\:([a-z]+))?>(.+?)<\/source>([\t\n])?)/m
|
5
|
+
CODERAY_OPTIONS = {:wrap => nil, :css => :class}
|
6
|
+
|
7
|
+
def preprocess_with_syntax_highlighting(text)
|
8
|
+
text.gsub(SOURCE_TAG_REGEXP) do |m|
|
9
|
+
all_of_it = $~[1]
|
10
|
+
whitespace_before = $~[2]
|
11
|
+
lang = ($~[3] || :ruby).to_sym
|
12
|
+
code = $~[4].strip
|
13
|
+
whitespace_after = $~[5]
|
14
|
+
|
15
|
+
wrap_in = all_of_it =~ /\n/ ? MULTI_LINE : SINGLE_LINE
|
16
|
+
highlighted = wrap_in % CodeRay.scan(code, lang).div(CODERAY_OPTIONS)
|
17
|
+
|
18
|
+
"#{whitespace_before}<notextile>#{highlighted}</notextile>#{whitespace_after}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.coderay_options(options)
|
23
|
+
CODERAY_OPTIONS.replace(options)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
redcloth_thingie = RedCloth::VERSION.to_s < "4" ? RedCloth : RedCloth::TextileDoc
|
28
|
+
|
29
|
+
redcloth_thingie.class_eval {
|
30
|
+
alias_method :_initialize, :initialize
|
31
|
+
|
32
|
+
def initialize(text, *args)
|
33
|
+
text = preprocess_with_syntax_highlighting(text)
|
34
|
+
_initialize(text, *args)
|
35
|
+
end
|
36
|
+
}
|
37
|
+
|
38
|
+
redcloth_thingie.send(:include, RedclothCoderay)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "redclothcoderay"
|
3
|
+
s.version = "0.3.5"
|
4
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
5
|
+
s.date = Time.now
|
6
|
+
s.authors = ['August Lilleaas', 'Matias Korhonen']
|
7
|
+
s.email = "augustlilleaas@gmail.com"
|
8
|
+
s.files = ["lib", "lib/redclothcoderay.rb", "MIT-LICENSE", "Rakefile", "README.rdoc", "redclothcoderay.gemspec", "test", "test/coderay_options_test.rb", "test/redclothcoderay_test.rb", "test/test_helper.rb"]
|
9
|
+
s.rubyforge_project = "redclothcoderay"
|
10
|
+
s.has_rdoc = true
|
11
|
+
s.add_dependency('RedCloth')
|
12
|
+
s.add_dependency('coderay')
|
13
|
+
s.summary = "Integrates CodeRay with RedCloth by adding a <source> tag."
|
14
|
+
s.homepage = "http://redclothcoderay.rubyforge.org"
|
15
|
+
s.description = %q{Adds CodeRay syntax highlighting support to RedCloth, with a ‘source’ tag.}
|
16
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'RedCloth'
|
3
|
+
require 'redclothcoderay'
|
4
|
+
|
5
|
+
class CoderayOptionsTest < Test::Unit::TestCase
|
6
|
+
def test_it
|
7
|
+
RedclothCoderay.coderay_options :line_numbers => :table
|
8
|
+
assert_equal :table, RedclothCoderay::CODERAY_OPTIONS[:line_numbers]
|
9
|
+
assert RedCloth.new("<source>ugly_inline :stuff</source>").to_html(:refs_syntax_highlighter).include?(%{<table class="CodeRay"})
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_it_with_code_tag
|
13
|
+
RedclothCoderay.coderay_options :line_numbers => :table
|
14
|
+
assert_equal :table, RedclothCoderay::CODERAY_OPTIONS[:line_numbers]
|
15
|
+
assert RedCloth.new("<code>ugly_inline :stuff</code>").to_html(:refs_syntax_highlighter).include?(%{<table class="CodeRay"})
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'redclothcoderay'
|
3
|
+
|
4
|
+
class PluginTest < Test::Unit::TestCase
|
5
|
+
def test_parsing_inline_code
|
6
|
+
text = "Hello, this is *textilized*. It also has <source>@inline_code_examples</source>!"
|
7
|
+
result = RedCloth.new(text).to_html
|
8
|
+
|
9
|
+
assert_equal(%Q{<p>Hello, this is <strong>textilized</strong>. It also has <code class="inline_code"><span class="iv">@inline_code_examples</span></code>!</p>}, result)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_parsing_multiline_code
|
13
|
+
text = %Q{Hello, this is *textilized*.
|
14
|
+
<source>
|
15
|
+
def hello_world
|
16
|
+
puts "Allright"
|
17
|
+
end
|
18
|
+
</source>}
|
19
|
+
result = RedCloth.new(text).to_html
|
20
|
+
|
21
|
+
assert result.include?(%Q{<strong>textilized</strong>})
|
22
|
+
assert result.include?(%Q{<div class="multiline_code">})
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_one_liner_multiline_code
|
26
|
+
text = %Q{Hello, this is *textilized*.
|
27
|
+
|
28
|
+
<source>
|
29
|
+
hello_to_you
|
30
|
+
</source>
|
31
|
+
}
|
32
|
+
result = RedCloth.new(text).to_html
|
33
|
+
|
34
|
+
assert result.include?(%Q{<strong>textilized</strong>})
|
35
|
+
assert result.include?(%Q{<div class=\"multiline_code\">hello_to_you</div>})
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_parsing_other_languages
|
39
|
+
text = %Q{Hello, this is *textilized* with some <source:html><p>HTML code</p></source>!}
|
40
|
+
result = RedCloth.new(text).to_html
|
41
|
+
|
42
|
+
assert result.include?(%Q{<strong>textilized</strong>})
|
43
|
+
assert result.include?(%Q{<code class="inline_code"><span class="ta"><p></span>HTML code<span class="ta"></p></span></code>})
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_after_a_header
|
47
|
+
text = %Q{h2. Hello, world.
|
48
|
+
|
49
|
+
<source>
|
50
|
+
hello_world
|
51
|
+
</source>}
|
52
|
+
result = RedCloth.new(text).to_html
|
53
|
+
assert result.include?(%Q{<h2>Hello, world.</h2>})
|
54
|
+
end
|
55
|
+
|
56
|
+
# This case is a real case that caused borks, which lead to 0.3.0.
|
57
|
+
def test_odd_indents
|
58
|
+
text = %Q{Let's try, now.
|
59
|
+
|
60
|
+
<source>
|
61
|
+
class Person < ActiveRecord::Base
|
62
|
+
composed_of :address, :class_name => "Address",
|
63
|
+
:mapping => [
|
64
|
+
[:address_street, :street],
|
65
|
+
[:address_postal_code, :postal_code]]
|
66
|
+
end
|
67
|
+
</source>}
|
68
|
+
|
69
|
+
result = RedCloth.new(text).to_html
|
70
|
+
|
71
|
+
assert result.include?(%{[<span class="sy">:address_street</span>, <span class="sy">:street</span>],})
|
72
|
+
assert result.include?(%{composed_of <span class="sy">:address</span>, <span class="sy">:class_name</span> => <span class="s"><span class="dl">"</span><span class="k">Address</span><span class="dl">"</span></span>,})
|
73
|
+
end
|
74
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: k33l0r-redclothcoderay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- August Lilleaas
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-09-
|
13
|
+
date: 2009-09-09 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -33,7 +33,7 @@ dependencies:
|
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: "0"
|
35
35
|
version:
|
36
|
-
description: "Adds CodeRay syntax highlighting support to RedCloth, with a \xE2\x80\x98source\xE2\x80\x99 tag.
|
36
|
+
description: "Adds CodeRay syntax highlighting support to RedCloth, with a \xE2\x80\x98source\xE2\x80\x99 tag."
|
37
37
|
email: augustlilleaas@gmail.com
|
38
38
|
executables: []
|
39
39
|
|
@@ -41,8 +41,17 @@ extensions: []
|
|
41
41
|
|
42
42
|
extra_rdoc_files: []
|
43
43
|
|
44
|
-
files:
|
45
|
-
|
44
|
+
files:
|
45
|
+
- lib
|
46
|
+
- lib/redclothcoderay.rb
|
47
|
+
- MIT-LICENSE
|
48
|
+
- Rakefile
|
49
|
+
- README.rdoc
|
50
|
+
- redclothcoderay.gemspec
|
51
|
+
- test
|
52
|
+
- test/coderay_options_test.rb
|
53
|
+
- test/redclothcoderay_test.rb
|
54
|
+
- test/test_helper.rb
|
46
55
|
has_rdoc: true
|
47
56
|
homepage: http://redclothcoderay.rubyforge.org
|
48
57
|
post_install_message:
|