redclothcoderay 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +9 -0
- data/Manifest +2 -2
- data/README +42 -17
- data/Rakefile +1 -1
- data/lib/redcloth_with_coderay.rb +26 -5
- data/redclothcoderay.gemspec +3 -3
- data/test/redclothcoderay_test.rb +0 -3
- metadata +4 -6
- data/lib/redcloth_with_coderay/customized_textile_helper.rb +0 -5
- data/lib/redcloth_with_coderay/redcloth_extension.rb +0 -24
data/CHANGELOG
ADDED
data/Manifest
CHANGED
data/README
CHANGED
@@ -1,25 +1,50 @@
|
|
1
|
-
|
1
|
+
== Redcloth with CodeRay
|
2
2
|
|
3
|
-
|
3
|
+
Adds CodeRay syntax highlighting support to RedCloth, with a 'source' tag. See the examples below.
|
4
4
|
|
5
|
-
|
5
|
+
A short summary of what you can do:
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
+
|
10
|
+
== Installing
|
11
|
+
|
12
|
+
Installation as usual:
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
sudo gem install redcloth
|
15
|
+
|
16
|
+
|
17
|
+
== Using
|
16
18
|
|
17
|
-
|
19
|
+
You have to specify that you want to use refs_syntax_highlighter when calling RedCloth#to_html.
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
21
|
+
require 'rubygems'
|
22
|
+
require 'redcloth'
|
23
|
+
require 'coderay'
|
24
|
+
require 'redclothcoderay'
|
25
|
+
|
26
|
+
RedCloth.new('I am *bold* and <source>@hi_tech</source>').to_html(:textile, :refs_syntax_highlighter)
|
22
27
|
|
23
|
-
|
28
|
+
== Example
|
24
29
|
|
25
|
-
|
30
|
+
This input:
|
31
|
+
|
32
|
+
Hello, this is *textilized*. It also has <source>@inline_code_examples</source>!
|
33
|
+
|
34
|
+
What about a multi-line code sample?
|
35
|
+
|
36
|
+
<source:html>
|
37
|
+
<h1>Hello, world!</h1>
|
38
|
+
</source>
|
39
|
+
|
40
|
+
produces this output (indented for clarity):
|
41
|
+
|
42
|
+
<p>Hello, this is <strong>textilized</strong>. It also has <code class="inline_code">
|
43
|
+
<span class="iv">@inline_code_examples</span>
|
44
|
+
</code>!</p>
|
45
|
+
|
46
|
+
<p>What about a multi-line code sample?</p>
|
47
|
+
|
48
|
+
<pre><code class=\"multiline_code\">
|
49
|
+
<span class=\"ta\">&lt;h1&gt;</span>Hello, world!<span class=\"ta\">&lt;/h1&gt;</span>
|
50
|
+
</code></pre>
|
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('redclothcoderay', '0.1.
|
5
|
+
Echoe.new('redclothcoderay', '0.1.1') do |p|
|
6
6
|
p.description = "Integrates CodeRay with RedCloth by adding a <source> tag."
|
7
7
|
p.url = "http://redclothcoderay.rubyforge.org/"
|
8
8
|
p.author = "August Lilleaas"
|
@@ -1,7 +1,28 @@
|
|
1
|
-
|
1
|
+
class String
|
2
|
+
# Utility method to check if a string contains newlines.
|
3
|
+
def contains_newlines?
|
4
|
+
self =~ /\n/
|
5
|
+
end
|
6
|
+
end
|
2
7
|
|
3
|
-
|
4
|
-
|
8
|
+
module RedclothWithCoderay
|
9
|
+
SINGLE_LINE = '<code class="inline_code">%s</code>'
|
10
|
+
MULTI_LINE = '<pre><code class="multiline_code">%s</code></pre>'
|
11
|
+
WRAPPER = '<notextile>%s</notextile>'
|
12
|
+
SOURCE_TAG_REGEXP = /([\t\n]?<source(?:\:([a-z]+))?>(.+?)<\/source>[\t\n]?)/m
|
13
|
+
|
14
|
+
# The RedCloth extension that performs the syntax highlighting.
|
15
|
+
def refs_syntax_highlighter(text)
|
16
|
+
text.gsub!(SOURCE_TAG_REGEXP) do |m|
|
17
|
+
all_of_it = $~[1]
|
18
|
+
lang = ($~[2] || :ruby).to_sym
|
19
|
+
code = $~[3].strip
|
20
|
+
|
21
|
+
wrap_in = all_of_it.contains_newlines? ? MULTI_LINE : SINGLE_LINE
|
22
|
+
highlighted = wrap_in % CodeRay.scan(code, lang).div(:wrap => nil, :css => :class)
|
23
|
+
WRAPPER % highlighted
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
5
27
|
|
6
|
-
RedCloth.class_eval { include RedclothWithCoderay }
|
7
|
-
ActionView::Helpers.class_eval { include CustomizedTextileHelper }
|
28
|
+
RedCloth.class_eval { include RedclothWithCoderay }
|
data/redclothcoderay.gemspec
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{redclothcoderay}
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.1"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["August Lilleaas"]
|
9
9
|
s.date = %q{2008-11-18}
|
10
10
|
s.description = %q{Integrates CodeRay with RedCloth by adding a <source> tag.}
|
11
11
|
s.email = %q{augustlilleaas@gmail.com}
|
12
|
-
s.extra_rdoc_files = ["
|
13
|
-
s.files = ["
|
12
|
+
s.extra_rdoc_files = ["CHANGELOG", "lib/redcloth_with_coderay.rb", "README"]
|
13
|
+
s.files = ["CHANGELOG", "lib/redcloth_with_coderay.rb", "Manifest", "MIT-LICENSE", "Rakefile", "README", "redclothcoderay.gemspec", "test/redclothcoderay_test.rb"]
|
14
14
|
s.has_rdoc = true
|
15
15
|
s.homepage = %q{http://redclothcoderay.rubyforge.org/}
|
16
16
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Redclothcoderay", "--main", "README"]
|
@@ -3,9 +3,6 @@ require 'redcloth'
|
|
3
3
|
require 'coderay'
|
4
4
|
require 'test/unit'
|
5
5
|
|
6
|
-
require 'action_controller'
|
7
|
-
require 'action_controller/test_process'
|
8
|
-
|
9
6
|
current_directory = File.dirname(__FILE__)
|
10
7
|
$:.unshift File.join(current_directory, '..', 'lib')
|
11
8
|
require 'redcloth_with_coderay'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redclothcoderay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- August Lilleaas
|
@@ -49,20 +49,18 @@ executables: []
|
|
49
49
|
extensions: []
|
50
50
|
|
51
51
|
extra_rdoc_files:
|
52
|
-
-
|
53
|
-
- lib/redcloth_with_coderay/redcloth_extension.rb
|
52
|
+
- CHANGELOG
|
54
53
|
- lib/redcloth_with_coderay.rb
|
55
54
|
- README
|
56
55
|
files:
|
57
|
-
-
|
58
|
-
- lib/redcloth_with_coderay/redcloth_extension.rb
|
56
|
+
- CHANGELOG
|
59
57
|
- lib/redcloth_with_coderay.rb
|
60
58
|
- Manifest
|
61
59
|
- MIT-LICENSE
|
62
60
|
- Rakefile
|
63
61
|
- README
|
64
|
-
- test/redclothcoderay_test.rb
|
65
62
|
- redclothcoderay.gemspec
|
63
|
+
- test/redclothcoderay_test.rb
|
66
64
|
has_rdoc: true
|
67
65
|
homepage: http://redclothcoderay.rubyforge.org/
|
68
66
|
post_install_message:
|
@@ -1,24 +0,0 @@
|
|
1
|
-
class String
|
2
|
-
def contains_newlines?
|
3
|
-
self =~ /\n/
|
4
|
-
end
|
5
|
-
end
|
6
|
-
|
7
|
-
module RedclothWithCoderay
|
8
|
-
SINGLE_LINE = '<code class="inline_code">%s</code>'
|
9
|
-
MULTI_LINE = '<pre><code class="multiline_code">%s</code></pre>'
|
10
|
-
WRAPPER = '<notextile>%s</notextile>'
|
11
|
-
SOURCE_TAG_REGEXP = /([\t\n]?<source(?:\:([a-z]+))?>(.+?)<\/source>[\t\n]?)/m
|
12
|
-
|
13
|
-
def refs_syntax_highlighter(text)
|
14
|
-
text.gsub!(SOURCE_TAG_REGEXP) do |m|
|
15
|
-
all_of_it = $~[1]
|
16
|
-
lang = ($~[2] || :ruby).to_sym
|
17
|
-
code = $~[3].strip
|
18
|
-
|
19
|
-
wrap_in = all_of_it.contains_newlines? ? MULTI_LINE : SINGLE_LINE
|
20
|
-
highlighted = wrap_in % CodeRay.scan(code, lang).div(:wrap => nil, :css => :class)
|
21
|
-
WRAPPER % highlighted
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|