leethal-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/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/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: leethal-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
|
@@ -46,20 +46,18 @@ executables: []
|
|
46
46
|
extensions: []
|
47
47
|
|
48
48
|
extra_rdoc_files:
|
49
|
-
-
|
50
|
-
- lib/redcloth_with_coderay/redcloth_extension.rb
|
49
|
+
- CHANGELOG
|
51
50
|
- lib/redcloth_with_coderay.rb
|
52
51
|
- README
|
53
52
|
files:
|
54
|
-
-
|
55
|
-
- lib/redcloth_with_coderay/redcloth_extension.rb
|
53
|
+
- CHANGELOG
|
56
54
|
- lib/redcloth_with_coderay.rb
|
57
55
|
- Manifest
|
58
56
|
- MIT-LICENSE
|
59
57
|
- Rakefile
|
60
58
|
- README
|
61
|
-
- test/redclothcoderay_test.rb
|
62
59
|
- redclothcoderay.gemspec
|
60
|
+
- test/redclothcoderay_test.rb
|
63
61
|
has_rdoc: true
|
64
62
|
homepage: http://redclothcoderay.rubyforge.org/
|
65
63
|
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
|