lesstile 0.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/History.txt +4 -0
- data/Manifest.txt +0 -1
- data/README.txt +6 -2
- data/Rakefile +16 -15
- data/VERSION +1 -0
- data/lib/lesstile.rb +13 -5
- data/spec/spec_lesstile.rb +38 -1
- metadata +24 -28
- data/bin/lesstile +0 -0
data/.gitignore
ADDED
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
data/README.txt
CHANGED
@@ -10,6 +10,7 @@ Integrates with CodeRay for sexy syntax highlighting.
|
|
10
10
|
== SYNOPSIS:
|
11
11
|
|
12
12
|
comment = <<-EOS
|
13
|
+
"Ego Link":http://rhnh.net
|
13
14
|
Wow, this post is awesome. I'd implement it like this:
|
14
15
|
|
15
16
|
--- Ruby
|
@@ -35,9 +36,12 @@ Integrates with CodeRay for sexy syntax highlighting.
|
|
35
36
|
|
36
37
|
* CodeRay (optional)
|
37
38
|
|
38
|
-
== INSTALL:
|
39
|
+
== INSTALL (pick one):
|
39
40
|
|
40
|
-
sudo gem install lesstile
|
41
|
+
sudo gem install lesstile # gem install
|
42
|
+
git clone git://github.com/xaviershay/lesstile.git # go from source
|
43
|
+
|
44
|
+
Tested on ruby 1.8.6-339, 1.8.7-160 and 1.9.1-rc2
|
41
45
|
|
42
46
|
== LICENSE:
|
43
47
|
|
data/Rakefile
CHANGED
@@ -1,21 +1,22 @@
|
|
1
|
-
|
1
|
+
begin
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |gemspec|
|
4
|
+
gemspec.name = "lesstile"
|
5
|
+
gemspec.summary = "Format text using an exceedingly simple markup language - perfect for comments on your blog"
|
6
|
+
gemspec.description = <<-EOS
|
7
|
+
Converts text formatted with an exceedingly simple markup language into XHTML (iron clad guarantee!) - perfect for comments on your blog. Textile isn't good for this because not only does it do too much (do commenters really need subscript?), but it can also output invalid HTML (try a <b> tag over multiple lines...). Whitelisting HTML is another option, but you still need some sort of parsing if you want syntax highlighting.
|
2
8
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
p.email = 'xavier@rhnh.net'
|
12
|
-
p.summary = 'Format text using an exceedingly simple markup language - perfect for comments on your blog'
|
13
|
-
p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
|
14
|
-
p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
|
15
|
-
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
16
|
-
p.remote_rdoc_dir = ""
|
9
|
+
Integrates with CodeRay for sexy syntax highlighting.
|
10
|
+
EOS
|
11
|
+
gemspec.email = "contact@rhnh.net"
|
12
|
+
gemspec.homepage = "http://github.com/xaviershay/lesstile"
|
13
|
+
gemspec.authors = ["Xavier Shay"]
|
14
|
+
end
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler not available. Install it with: sudo gem install jeweler"
|
17
17
|
end
|
18
18
|
|
19
|
+
require 'spec/rake/spectask'
|
19
20
|
Spec::Rake::SpecTask.new do |t|
|
20
21
|
t.warning = false
|
21
22
|
t.rcov = false
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.3.0
|
data/lib/lesstile.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
require 'cgi'
|
2
|
+
require 'uri'
|
2
3
|
|
3
4
|
class Lesstile
|
4
|
-
VERSION = '0.
|
5
|
+
VERSION = '0.3'
|
6
|
+
|
7
|
+
CodeDetectionRegex = /---\s*?([\w\s\._+()-]*?)\s*?\n(.*?)---\n/m
|
5
8
|
|
6
9
|
class << self
|
7
10
|
# Returns lesstile formatted text as valid XHTML
|
@@ -16,13 +19,12 @@ class Lesstile
|
|
16
19
|
text.gsub!(/\r\n/, "\n")
|
17
20
|
text = CGI::escapeHTML(text)
|
18
21
|
|
19
|
-
code_regex = /---\s*?(\w*?)\s*?\n(.*?)---\n/m
|
20
22
|
output = ""
|
21
23
|
|
22
|
-
while match = text.match(
|
24
|
+
while match = text.match(CodeDetectionRegex)
|
23
25
|
captures = match.captures
|
24
26
|
code = captures[1]
|
25
|
-
lang = blank?(captures[0]) ? nil : captures[0].downcase.intern
|
27
|
+
lang = blank?(captures[0]) ? nil : captures[0].downcase.strip.intern
|
26
28
|
|
27
29
|
output += options[:text_formatter][match.pre_match] + options[:code_formatter][code, lang]
|
28
30
|
text = match.post_match
|
@@ -35,7 +37,13 @@ class Lesstile
|
|
35
37
|
def default_options
|
36
38
|
{
|
37
39
|
:code_formatter => lambda {|code, lang| "<pre><code>#{code}</code></pre>" },
|
38
|
-
:text_formatter => lambda {|text|
|
40
|
+
:text_formatter => lambda {|text|
|
41
|
+
text = text.dup
|
42
|
+
text.gsub!(/\n/, "<br />\n")
|
43
|
+
text.gsub!('"', '"')
|
44
|
+
text.gsub!(Regexp.new('"([^"]+)":(' + URI.regexp.to_s + ')'), '<a href="\2">\1</a>')
|
45
|
+
text
|
46
|
+
}
|
39
47
|
}
|
40
48
|
end
|
41
49
|
|
data/spec/spec_lesstile.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'rubygems'
|
1
2
|
require 'spec'
|
2
3
|
require File.dirname(__FILE__) + '/../lib/lesstile'
|
3
4
|
|
@@ -6,7 +7,7 @@ describe "Lesstile#format_as_xhtml" do
|
|
6
7
|
@lesstile = Lesstile
|
7
8
|
@format = lambda {|text|
|
8
9
|
@lesstile.format_as_xhtml(text,
|
9
|
-
:code_formatter => lambda {|code, lang| "|#{code}|" },
|
10
|
+
:code_formatter => lambda {|code, lang| "|#{"(#{lang})" if lang}#{code}|" },
|
10
11
|
:text_formatter => lambda {|text| text }
|
11
12
|
)
|
12
13
|
}
|
@@ -25,6 +26,18 @@ describe "Lesstile#format_as_xhtml" do
|
|
25
26
|
it "surrounds code blocks in appropriate tags" do
|
26
27
|
@format["---\nhello\n---\n"].should == "|hello\n|"
|
27
28
|
end
|
29
|
+
|
30
|
+
it "parses code blocks with language specified" do
|
31
|
+
@format["--- abc\nhello\n---\n"].should == "|(abc)hello\n|"
|
32
|
+
end
|
33
|
+
|
34
|
+
# spaces, dashes, plusses, normal, underscore, brackets, numbers, dots
|
35
|
+
["Ruby on Rails", "Objective-C", "Objective-C++",
|
36
|
+
"Python", "_SQL_", "(X)HTML", "CSS3", "Javascript1.2"].each do |language|
|
37
|
+
it "parses code blocks with language #{language}" do
|
38
|
+
@format["--- #{language}\nhello\n---\n"].should == "|(#{language.downcase})hello\n|"
|
39
|
+
end
|
40
|
+
end
|
28
41
|
|
29
42
|
it "parses code blocks at end of input" do
|
30
43
|
@format["---\nhello\n---"].should == "|hello\n|"
|
@@ -44,6 +57,30 @@ describe "Lesstile#format_as_xhtml" do
|
|
44
57
|
it 'escapes html' do
|
45
58
|
@format["<a>&---\nyo<---"].should == "<a>&|yo<|"
|
46
59
|
end
|
60
|
+
|
61
|
+
it 'escapes quotes' do
|
62
|
+
@format['"'].should == """
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe 'Lesstile default text formatter' do
|
67
|
+
before(:all) do
|
68
|
+
@format = lambda {|text| Lesstile.default_options[:text_formatter][text] }
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'recognises links in text' do
|
72
|
+
@format[CGI::escapeHTML('"a link":http://example.com "<link":http://example.com linkage')].should ==
|
73
|
+
'<a href="http://example.com">a link</a> <a href="http://example.com"><link</a> linkage'
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'does not recognise blank links' do
|
77
|
+
text = '"":http://example.com'
|
78
|
+
@format[CGI::escapeHTML(text)].should == text
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'unescapes " since it is not dangerous in plain text and allows us to use a simple regex for link formatting' do
|
82
|
+
@format["""].should == '"'
|
83
|
+
end
|
47
84
|
end
|
48
85
|
|
49
86
|
describe "Lesstile#format_with_xhtml with default formatters" do
|
metadata
CHANGED
@@ -1,50 +1,46 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lesstile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
platform:
|
4
|
+
version: 0.3.0
|
5
|
+
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Xavier Shay
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-10-28 00:00:00 +11:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
description: "Integrates with CodeRay for sexy syntax highlighting. == SYNOPSIS: comment = <<-EOS Wow, this post is awesome. I'd implement it like this: --- Ruby def hello_world puts \"hello world!\" end ---"
|
25
|
-
email: xavier@rhnh.net
|
26
|
-
executables:
|
27
|
-
- lesstile
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: |
|
17
|
+
Converts text formatted with an exceedingly simple markup language into XHTML (iron clad guarantee!) - perfect for comments on your blog. Textile isn't good for this because not only does it do too much (do commenters really need subscript?), but it can also output invalid HTML (try a <b> tag over multiple lines...). Whitelisting HTML is another option, but you still need some sort of parsing if you want syntax highlighting.
|
18
|
+
|
19
|
+
Integrates with CodeRay for sexy syntax highlighting.
|
20
|
+
|
21
|
+
email: contact@rhnh.net
|
22
|
+
executables: []
|
23
|
+
|
28
24
|
extensions: []
|
29
25
|
|
30
26
|
extra_rdoc_files:
|
31
|
-
- History.txt
|
32
|
-
- Manifest.txt
|
33
27
|
- README.txt
|
34
28
|
files:
|
29
|
+
- .gitignore
|
35
30
|
- History.txt
|
36
31
|
- Manifest.txt
|
37
32
|
- README.txt
|
38
33
|
- Rakefile
|
39
|
-
-
|
34
|
+
- VERSION
|
40
35
|
- lib/lesstile.rb
|
41
36
|
- spec/spec_lesstile.rb
|
42
37
|
has_rdoc: true
|
43
|
-
homepage:
|
38
|
+
homepage: http://github.com/xaviershay/lesstile
|
39
|
+
licenses: []
|
40
|
+
|
44
41
|
post_install_message:
|
45
42
|
rdoc_options:
|
46
|
-
- --
|
47
|
-
- README.txt
|
43
|
+
- --charset=UTF-8
|
48
44
|
require_paths:
|
49
45
|
- lib
|
50
46
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -61,10 +57,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
57
|
version:
|
62
58
|
requirements: []
|
63
59
|
|
64
|
-
rubyforge_project:
|
65
|
-
rubygems_version:
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 1.3.4
|
66
62
|
signing_key:
|
67
|
-
specification_version:
|
63
|
+
specification_version: 3
|
68
64
|
summary: Format text using an exceedingly simple markup language - perfect for comments on your blog
|
69
|
-
test_files:
|
70
|
-
|
65
|
+
test_files:
|
66
|
+
- spec/spec_lesstile.rb
|
data/bin/lesstile
DELETED
File without changes
|