texttube_baby 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGES.md +8 -0
- data/Gemfile +3 -0
- data/lib/texttube/baby/coderay.rb +35 -27
- data/lib/texttube/baby/inside_block.rb +9 -7
- data/lib/texttube/baby/link_reffing.rb +1 -1
- data/lib/texttube/baby/spiffing.rb +1 -2
- data/lib/texttube/baby/version.rb +1 -1
- data/lib/texttube/baby.rb +0 -1
- data/spec/inside_block_spec.rb +1 -2
- data/spec/link_reffing_spec.rb +80 -43
- data/spec/markdownfilters_spec.rb +7 -7
- data/texttube_baby.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c03a1149bdebebe406574df28daf4535cfef08a
|
4
|
+
data.tar.gz: 663ed918d62ef4dd27291a0fba5e1be2f629cc12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24149e6b053b362a72c6bb380ffc9b303c848c7f6ee44b5964beb7c485c616097d1d03f35af62b9f82f1e337b27db6a47894e6d0b731b0f32ad45b61bf49c05d
|
7
|
+
data.tar.gz: 0f2b5720a574478efbb1a07a3c0b5bc06ec515ed91e2eebd27151698f63d6da2a8a540efe202c6407116b396da315ab289ab15e751140ee93b8f03d1855a0919
|
data/.gitignore
CHANGED
data/CHANGES.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
## CH CH CH CH CHANGES! ##
|
2
2
|
|
3
|
+
|
4
|
+
### Monday the 8th of June 2015, v1.1.0 ###
|
5
|
+
|
6
|
+
* Changed from Nokogiri to Oga because Nokogiri is annoying to install. Having said that, getting a bugfix into Oga was annoying too, so for now it will rely on my patched library, Oga Without the Wimpiness. This will be replaced by Oga in the next release when *it* is next released.
|
7
|
+
|
8
|
+
----
|
9
|
+
|
10
|
+
|
3
11
|
### Friday the 17th of October 2014, v1.0.0 ###
|
4
12
|
|
5
13
|
* All specs passing, library now separated from TextTube.
|
data/Gemfile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
module TextTube
|
3
3
|
|
4
|
-
require '
|
4
|
+
require 'oga'
|
5
5
|
require_relative "../../ext/blank.rb"
|
6
6
|
require 'coderay'
|
7
7
|
require "texttube/filterable"
|
@@ -9,6 +9,8 @@ module TextTube
|
|
9
9
|
module Baby
|
10
10
|
|
11
11
|
# a filter for Coderay
|
12
|
+
# @note Thanks to Rob Emerson for sharing his nanoc filter which helped me write this.
|
13
|
+
# @see http://www.remerson.plus.com/articles/nanoc-coderay/
|
12
14
|
module Coderay
|
13
15
|
extend Filterable
|
14
16
|
|
@@ -21,37 +23,44 @@ module TextTube
|
|
21
23
|
# @param [Hash] options
|
22
24
|
# @return [String]
|
23
25
|
def self.run(content, options={})
|
24
|
-
options = {lang: :ruby } if options.blank?
|
25
|
-
doc =
|
26
|
+
options = {lang: :ruby } if options.blank?
|
27
|
+
doc = Oga.parse_html content
|
26
28
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
# following the convention of Rack::Codehighlighter
|
32
|
-
if inner_html.start_with?("::::")
|
33
|
-
lines = inner_html.split("\n")
|
34
|
-
options[:lang] = lines.shift.match(%r{::::(\w+)})[1].to_sym
|
35
|
-
inner_html = lines.join("\n")
|
36
|
-
end
|
29
|
+
if (xpath = doc.xpath("pre/code"))
|
30
|
+
xpath.map do |codeblock|
|
31
|
+
#un-escape as Coderay will escape it again
|
32
|
+
inner_html = codeblock.inner_text
|
37
33
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
end
|
45
|
-
end#block
|
34
|
+
# following the convention of Rack::Codehighlighter
|
35
|
+
if inner_html.start_with?("::::")
|
36
|
+
lines = inner_html.split("\n")
|
37
|
+
options[:lang] = lines.shift.match(%r{::::(\w+)})[1].to_sym
|
38
|
+
inner_html = lines.join("\n")
|
39
|
+
end
|
46
40
|
|
47
|
-
|
41
|
+
if (options[:lang] == :skip) || (! options.has_key? :lang )
|
42
|
+
codeblock.inner_text = inner_html
|
43
|
+
else
|
44
|
+
# html_unescape(inner_html)
|
45
|
+
# code = codify(html_unescape(inner_html), options[:lang])
|
46
|
+
code = Coderay.codify(Coderay.html_unescape(inner_html), options[:lang])
|
47
|
+
# It needs to be parsed back into Oga
|
48
|
+
# or the escaping goes wrong
|
49
|
+
codeblock.children= Oga.parse_html( code ).children
|
50
|
+
codeblock.set "class", "CodeRay"
|
51
|
+
end
|
52
|
+
end#block
|
53
|
+
doc.to_xml
|
54
|
+
else
|
55
|
+
content
|
56
|
+
end
|
48
57
|
end#def
|
49
58
|
|
50
59
|
# @private
|
51
60
|
# Unescape the HTML as the Coderay scanner won't work otherwise.
|
52
|
-
def self.html_unescape(a_string)
|
61
|
+
def self.html_unescape(a_string)
|
53
62
|
a_string.gsub('&', '&').gsub('<', '<').gsub('>',
|
54
|
-
'>').gsub('"', '"')
|
63
|
+
'>').gsub('"', '"')
|
55
64
|
end#def
|
56
65
|
|
57
66
|
# Run the Coderay scanner.
|
@@ -60,11 +69,10 @@ module TextTube
|
|
60
69
|
# @param [String] lang
|
61
70
|
# @example
|
62
71
|
# self.class.codify "x = 2", "ruby"
|
63
|
-
def self.codify(str, lang)
|
72
|
+
def self.codify(str, lang)
|
64
73
|
::CodeRay.scan(str, lang).html
|
65
74
|
end#def
|
66
75
|
|
67
|
-
end#class
|
76
|
+
end#class
|
68
77
|
end
|
69
|
-
|
70
78
|
end#module
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
-
require 'nokogiri'
|
3
2
|
require "texttube/filterable"
|
3
|
+
require 'oga'
|
4
4
|
|
5
5
|
module TextTube
|
6
6
|
module Baby
|
@@ -19,17 +19,19 @@ module TextTube
|
|
19
19
|
def self.run( content, options={})
|
20
20
|
options ||= {}
|
21
21
|
if options[:markdown_parser].nil?
|
22
|
-
require 'rdiscount'
|
22
|
+
require 'rdiscount'
|
23
23
|
markdown_parser=RDiscount
|
24
24
|
end
|
25
|
-
doc =
|
25
|
+
doc = Oga.parse_html(content)
|
26
26
|
|
27
|
-
doc.xpath("*[@markdown='1']").each do |ele|
|
28
|
-
|
29
|
-
|
27
|
+
doc.xpath("*[@markdown='1']").each do |ele|
|
28
|
+
inner_text = ele.children.inject(""){|mem,child| mem << child.to_xml }
|
29
|
+
html_fragment = markdown_parser.new(inner_text).to_html
|
30
|
+
ele.children= Oga.parse_html( html_fragment ).children
|
31
|
+
ele.unset "markdown"
|
30
32
|
end
|
31
33
|
|
32
|
-
doc.
|
34
|
+
doc.to_xml
|
33
35
|
end # run
|
34
36
|
|
35
37
|
end
|
@@ -32,10 +32,9 @@ module TextTube
|
|
32
32
|
# @param [Hash] options
|
33
33
|
def self.run( content, options={})
|
34
34
|
ugly_child = content.dup
|
35
|
-
|
35
|
+
|
36
36
|
DICTIONARY.each do |english, ugly|
|
37
37
|
ugly_child.sub! english, ugly
|
38
|
-
# warn ugly_child
|
39
38
|
end
|
40
39
|
ugly_child
|
41
40
|
end
|
data/lib/texttube/baby.rb
CHANGED
data/spec/inside_block_spec.rb
CHANGED
data/spec/link_reffing_spec.rb
CHANGED
@@ -14,44 +14,80 @@ module Baby # convience
|
|
14
14
|
it { should == expected }
|
15
15
|
end
|
16
16
|
|
17
|
-
|
17
|
+
context "And markdown" do
|
18
|
+
require 'rdiscount'
|
19
|
+
let(:content) { <<CONTENT
|
20
|
+
# Some Example Links #
|
21
|
+
|
22
|
+
Example1[[http://example.org/abc/1234.5678|Example1 link]].
|
23
|
+
|
24
|
+
Example2[[http://example.com/ABC/0.1.2.3|Example2 link]].
|
25
|
+
CONTENT
|
26
|
+
}
|
27
|
+
let(:expected){<<HTML
|
28
|
+
<h1>Some Example Links</h1>
|
29
|
+
|
30
|
+
<p>Example1<a href="#0" title="Jump to reference">⁰</a>.</p>
|
31
|
+
|
32
|
+
<p>Example2<a href="#1" title="Jump to reference">¹</a>.</p>
|
18
33
|
|
19
|
-
context "and no options" do
|
20
|
-
subject { TextTube::Baby::LinkReffing.run content }
|
21
|
-
let(:expected) { s = <<HTML
|
22
|
-
The UtterFAIL website[⁰](#0 "Jump to reference") is good. My blog[¹](#1 "Jump to reference") is also good.
|
23
34
|
<div markdown='1' id='reflinks'>
|
24
|
-
<a name="0"></a>[0] [http://
|
35
|
+
<a name="0"></a>[0] [http://example.org/abc/1234.5678](http://example.org/abc/1234.5678 "http://example.org/abc/1234.5678") Example1 link
|
25
36
|
|
26
37
|
|
27
|
-
<a name="1"></a>[1] [http://
|
38
|
+
<a name="1"></a>[1] [http://example.com/ABC/0.1.2.3](http://example.com/ABC/0.1.2.3 "http://example.com/ABC/0.1.2.3") Example2 link
|
28
39
|
|
29
40
|
</div>
|
41
|
+
|
30
42
|
HTML
|
31
|
-
s.strip
|
32
|
-
}
|
33
|
-
include_examples "outputting links"
|
34
|
-
end
|
35
|
-
context "and an option not to ref the link (i.e. inline)" do
|
36
|
-
let(:expected) {
|
37
|
-
"The UtterFAIL website [UtterFAIL!](http://utterfail.info) is good. My blog [My blog](http://iainbarnett.me.uk) is also good."
|
38
43
|
}
|
39
44
|
subject {
|
40
|
-
TextTube::Baby::LinkReffing.run content
|
45
|
+
text = TextTube::Baby::LinkReffing.run content
|
46
|
+
RDiscount.new(text).to_html
|
41
47
|
}
|
42
48
|
include_examples "outputting links"
|
43
|
-
|
49
|
+
end # context
|
50
|
+
|
51
|
+
context "Given blah" do
|
52
|
+
|
53
|
+
let(:content) { "The UtterFAIL website[[http://utterfail.info|UtterFAIL!]] is good. My blog[[http://iainbarnett.me.uk|My blog]] is also good." }
|
54
|
+
|
55
|
+
context "and no options" do
|
56
|
+
subject { TextTube::Baby::LinkReffing.run content }
|
57
|
+
let(:expected) { s = <<HTML
|
58
|
+
The UtterFAIL website[⁰](#0 "Jump to reference") is good. My blog[¹](#1 "Jump to reference") is also good.
|
59
|
+
<div markdown='1' id='reflinks'>
|
60
|
+
<a name="0"></a>[0] [http://utterfail.info](http://utterfail.info "http://utterfail.info") UtterFAIL!
|
61
|
+
|
62
|
+
|
63
|
+
<a name="1"></a>[1] [http://iainbarnett.me.uk](http://iainbarnett.me.uk "http://iainbarnett.me.uk") My blog
|
64
|
+
|
65
|
+
</div>
|
66
|
+
HTML
|
67
|
+
s.strip
|
68
|
+
}
|
69
|
+
include_examples "outputting links"
|
70
|
+
end
|
71
|
+
context "and an option not to ref the link (i.e. inline)" do
|
44
72
|
let(:expected) {
|
45
|
-
|
73
|
+
"The UtterFAIL website [UtterFAIL!](http://utterfail.info) is good. My blog [My blog](http://iainbarnett.me.uk) is also good."
|
46
74
|
}
|
47
75
|
subject {
|
48
|
-
TextTube::Baby::LinkReffing.run content, kind: :inline
|
76
|
+
TextTube::Baby::LinkReffing.run content, kind: :inline
|
49
77
|
}
|
50
78
|
include_examples "outputting links"
|
79
|
+
context "and use HTML" do
|
80
|
+
let(:expected) {
|
81
|
+
%Q$The UtterFAIL website <a href="http://utterfail.info">UtterFAIL!</a> is good. My blog <a href="http://iainbarnett.me.uk">My blog</a> is also good.$
|
82
|
+
}
|
83
|
+
subject {
|
84
|
+
TextTube::Baby::LinkReffing.run content, kind: :inline, format: :html
|
85
|
+
}
|
86
|
+
include_examples "outputting links"
|
87
|
+
end
|
51
88
|
end
|
52
|
-
|
53
|
-
|
54
|
-
let(:expected) { s = <<HTML
|
89
|
+
context "and an option to output a link as HTML" do
|
90
|
+
let(:expected) { s = <<HTML
|
55
91
|
The UtterFAIL website<a href="#0" title="Jump to reference">⁰</a> is good. My blog<a href="#1" title="Jump to reference">¹</a> is also good.
|
56
92
|
<div markdown='1' id='reflinks'>
|
57
93
|
<a name="0"></a>[0] [http://utterfail.info](http://utterfail.info "http://utterfail.info") UtterFAIL!
|
@@ -61,31 +97,32 @@ The UtterFAIL website<a href="#0" title="Jump to reference">⁰</a> is good.
|
|
61
97
|
|
62
98
|
</div>
|
63
99
|
HTML
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
100
|
+
s.strip
|
101
|
+
}
|
102
|
+
subject { TextTube::Baby::LinkReffing.run content, format: :html }
|
103
|
+
include_examples "outputting links"
|
104
|
+
end
|
105
|
+
context "and an option to not show the link at all" do
|
106
|
+
let(:expected) { s = <<HTML
|
71
107
|
The UtterFAIL website is good. My blog is also good.
|
72
108
|
HTML
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
end # context
|
109
|
+
s.strip
|
110
|
+
}
|
111
|
+
subject {
|
112
|
+
TextTube::Baby::LinkReffing.run content, kind: :none
|
113
|
+
}
|
114
|
+
include_examples "outputting links"
|
115
|
+
end
|
81
116
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
117
|
+
context "With no link to be reffed in it" do
|
118
|
+
let(:content) { %Q$The [UtterFAIL website](http://utterfail.info/ "UtterFAIL!") is good.$ }
|
119
|
+
let(:expected) { content }
|
120
|
+
subject { TextTube::Baby::LinkReffing.run content }
|
121
|
+
it { should_not be_nil }
|
122
|
+
it { should == expected }
|
123
|
+
end # context
|
124
|
+
end # context blah
|
125
|
+
end
|
89
126
|
end # context
|
90
127
|
|
91
128
|
context "Given no text" do
|
@@ -111,14 +111,12 @@ MARKDOWN
|
|
111
111
|
context "An article that needs all the filters" do
|
112
112
|
before :all do
|
113
113
|
TextTube::Baby.load_all_filters
|
114
|
-
warn "HERE"
|
115
|
-
warn TextTube::Baby.constants
|
116
114
|
class MyFilter < TextTube::Base
|
117
|
-
register TextTube::Baby::Coderay
|
118
115
|
register TextTube::Baby::LinkReffing
|
119
116
|
register TextTube::Baby::EmbeddingAudio
|
120
117
|
register TextTube::Baby::EmbeddingVideo
|
121
118
|
register TextTube::Baby::InsideBlock
|
119
|
+
register TextTube::Baby::Coderay
|
122
120
|
register do
|
123
121
|
filter_with :rdiscount do |text|
|
124
122
|
RDiscount.new(text).to_html
|
@@ -169,8 +167,7 @@ rainfall 99_998
|
|
169
167
|
|
170
168
|
<p>Just to be clear, I ran this with Ruby 2.0.0-rc2 as well with the same results. It's a pity that Ruby fails at this kind of thing, because it is such an elegant and useful language that seems to have borrowed the best of many other niche languages. Recursion is often the most elegant <em>and</em> performant<a href="#1" title="Jump to reference">¹</a> solution.</p>
|
171
169
|
|
172
|
-
<div id="reflinks">
|
173
|
-
<p><a name="0"></a>[0] <a href="http://arxiv.org/abs/1304.5257" title="http://arxiv.org/abs/1304.5257">http://arxiv.org/abs/1304.5257</a> What Makes Code Hard to Understand? Michael Hansen, Robert L. Goldstone, Andrew Lumsdaine</p>
|
170
|
+
<div id="reflinks"><p><a name="0"></a>[0] <a href="http://arxiv.org/abs/1304.5257" title="http://arxiv.org/abs/1304.5257">http://arxiv.org/abs/1304.5257</a> What Makes Code Hard to Understand? Michael Hansen, Robert L. Goldstone, Andrew Lumsdaine</p>
|
174
171
|
|
175
172
|
<p><a name="1"></a>[1] <a href="http://dictionary.cambridge.org/dictionary/british/pedant" title="http://dictionary.cambridge.org/dictionary/british/pedant">http://dictionary.cambridge.org/dictionary/br...</a> If you're one of these then you won't like that I made a word up. Unfortunately for you, I'm British, which means that I understand that English is a living language, it is my tool not my master, and it has a long history of being changed to suit the speaker or writer. This is one such case.</p>
|
176
173
|
</div>
|
@@ -186,11 +183,14 @@ HTML
|
|
186
183
|
before :all do
|
187
184
|
MyFilter.options.merge! :linkreffing => {kind: :none}
|
188
185
|
end
|
189
|
-
subject { MyFilter.new(content).filter :embeddingvideo, :embeddingaudio, :linkreffing, :rdiscount
|
186
|
+
subject { MyFilter.new(content).filter :embeddingvideo, :embeddingaudio, :linkreffing, :rdiscount}#, :coderay, :insideblock }
|
190
187
|
it { should_not == expected }
|
191
188
|
|
192
189
|
context "and passed to filter" do
|
193
|
-
subject {
|
190
|
+
subject {
|
191
|
+
r = MyFilter.new(content).filter :embeddingvideo, :embeddingaudio, :linkreffing, :rdiscount, :coderay, :insideblock, :linkreffing => {kind: :reference}
|
192
|
+
r
|
193
|
+
}
|
194
194
|
it { should == expected }
|
195
195
|
end
|
196
196
|
end
|
data/texttube_baby.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
spec.add_dependency "texttube", ">= 6.0.0"
|
21
|
-
spec.add_dependency "
|
21
|
+
spec.add_dependency "oga-without-the-wimpiness"
|
22
22
|
spec.add_dependency "coderay"
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.7"
|
24
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: texttube_baby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Iain Barnett
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: texttube
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 6.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: oga-without-the-wimpiness
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
131
|
version: '0'
|
132
132
|
requirements: []
|
133
133
|
rubyforge_project:
|
134
|
-
rubygems_version: 2.
|
134
|
+
rubygems_version: 2.4.5
|
135
135
|
signing_key:
|
136
136
|
specification_version: 4
|
137
137
|
summary: Some useful filters for markdown that I use in my blogs
|