touch_up 2.0.0 → 3.0.0
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.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/touch_up.rb +44 -34
- data/specs/0010-it-runs.rb +19 -23
- data/specs/0011-escaping.rb +40 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21e2b827a0177d7b09510de6bddfdd1ece2d49d9
|
4
|
+
data.tar.gz: ff3e7c1f9f5515a14f2a2d160b8e9ae9cfba5381
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b4fb2f52a70eccf56802c4798291dacf3ea1572994610e461560220afa7a7e5eb87e42e881daabd7ee56347c79c43c7313840d6b89a0f61ad34f78377f3b697
|
7
|
+
data.tar.gz: dc76871bc2ed6d0ceaf73864b964da5e0fa4cc25d7e02a453a5b5e382f6bd5ba0aa170a576ca74f3017c27587da738555fc1700f2eeff6da078449737c7c8a33
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
3.0.0
|
data/lib/touch_up.rb
CHANGED
@@ -4,7 +4,9 @@ require 'twitter-text'
|
|
4
4
|
|
5
5
|
class Touch_Up
|
6
6
|
|
7
|
-
NOTHING
|
7
|
+
NOTHING = ''.freeze
|
8
|
+
HREFS = %r@(\*([^\*]+)\*\s+)?([^\.\s]+\.[^\.\s]+[^\s]+[^\.\s])@
|
9
|
+
MARK_DOWNS = /(\&\#47\;|~~|\*)([^\1\<\>]+)(\1)/
|
8
10
|
|
9
11
|
include Twitter::Extractor
|
10
12
|
|
@@ -16,36 +18,33 @@ class Touch_Up
|
|
16
18
|
end
|
17
19
|
|
18
20
|
def to_html
|
19
|
-
@origin.
|
21
|
+
splits = Escape_Escape_Escape.html(@origin).gsub(HREFS) { |full, match|
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
+
raw_text = $2 ? Escape_Escape_Escape.decode_html($2) : nil
|
24
|
+
raw_append = Escape_Escape_Escape.decode_html $3
|
25
|
+
raw_link = extract_urls(raw_append).first
|
23
26
|
|
24
|
-
|
25
|
-
raw_link = Escape_Escape_Escape.decode_html($3)
|
26
|
-
|
27
|
-
link = extract_urls(raw_link).first
|
28
|
-
|
29
|
-
if !link
|
27
|
+
if !raw_link
|
30
28
|
full
|
31
29
|
else
|
32
30
|
|
33
|
-
append
|
34
|
-
|
35
|
-
|
31
|
+
append = Escape_Escape_Escape.html raw_append.sub(raw_link, NOTHING)
|
32
|
+
text = if raw_text
|
33
|
+
Escape_Escape_Escape.html(raw_text)
|
34
|
+
else
|
35
|
+
Escape_Escape_Escape.html(raw_link)
|
36
|
+
end
|
37
|
+
|
38
|
+
raw_link = Escape_Escape_Escape.decode_html(raw_link)
|
36
39
|
|
37
|
-
if !
|
38
|
-
|
40
|
+
if !raw_link['://']
|
41
|
+
raw_link = 'http://' + raw_link
|
39
42
|
end
|
40
43
|
|
41
44
|
begin
|
42
|
-
|
45
|
+
link = Escape_Escape_Escape.href(raw_link)
|
43
46
|
|
44
|
-
|
45
|
-
"<a href=\"#{clean_link}\">#{text}</a>#{append}"
|
46
|
-
else
|
47
|
-
"<a href=\"#{clean_link}\">#{clean_short_link}</a>#{append}"
|
48
|
-
end
|
47
|
+
"<a href=\"#{link}\">#{text}</a>#{append}"
|
49
48
|
|
50
49
|
rescue Escape_Escape_Escape::Invalid_HREF
|
51
50
|
full
|
@@ -54,22 +53,33 @@ class Touch_Up
|
|
54
53
|
end # if
|
55
54
|
|
56
55
|
|
57
|
-
}.
|
58
|
-
|
56
|
+
}.split(/(\<[^\>]+\>[^\<]+\<\/[^\>]+\>)/)
|
59
57
|
|
60
58
|
# "i", "del", "strong" tags
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
59
|
+
final = ""
|
60
|
+
i = 0
|
61
|
+
while i < splits.size
|
62
|
+
final << (splits[i].gsub(MARK_DOWNS) { |full, match|
|
63
|
+
case
|
64
|
+
when $1 == $3 && $1 == '/'
|
65
|
+
"<i>#{$2}</i>"
|
66
|
+
when $1 == '~~' && $3 == '~~'
|
67
|
+
"<del>#{$2}</del>"
|
68
|
+
when $1 == $3 && $1 == '*'
|
69
|
+
"<strong>#{$2}</strong>"
|
70
|
+
else
|
71
|
+
full
|
72
|
+
end
|
73
|
+
})
|
74
|
+
|
75
|
+
i += 1
|
76
|
+
if splits[i]
|
77
|
+
final << splits[i]
|
78
|
+
i += 1
|
71
79
|
end
|
72
|
-
|
80
|
+
end
|
81
|
+
|
82
|
+
final
|
73
83
|
|
74
84
|
end
|
75
85
|
|
data/specs/0010-it-runs.rb
CHANGED
@@ -2,12 +2,8 @@
|
|
2
2
|
describe 'italics' do
|
3
3
|
|
4
4
|
it "turns slash-ed text into italics: /slash/ <i>slash</i>" do
|
5
|
-
|
6
|
-
This is my
|
7
|
-
EOF
|
8
|
-
text.to_html.strip.should == <<-EOF.strip
|
9
|
-
This is my <i>slash</i> text.
|
10
|
-
EOF
|
5
|
+
Touch_Up.new("This is my /slash/ text.").
|
6
|
+
to_html.strip.should == "This is my <i>slash</i> text."
|
11
7
|
end # === it turns slash-ed text into italics: /slash/ <i>slash</i>
|
12
8
|
|
13
9
|
it "leaves surrounding chars alone: I am super-/slanted/." do
|
@@ -20,10 +16,8 @@ end # === describe 'italics'
|
|
20
16
|
describe "strong" do
|
21
17
|
|
22
18
|
it "turns star-ed text to strong: *bold* <strong>bold</strong>" do
|
23
|
-
|
24
|
-
|
25
|
-
EOF
|
26
|
-
text.to_html.strip.should == <<-EOF.strip
|
19
|
+
Touch_Up.new("This is my brave and *bold* text.").
|
20
|
+
to_html.strip.should == <<-EOF.strip
|
27
21
|
This is my brave and <strong>bold</strong> text.
|
28
22
|
EOF
|
29
23
|
end # === it turns star-ed text to strong: *bold* <strong>bold</strong>
|
@@ -38,12 +32,8 @@ end # === describe "strong"
|
|
38
32
|
describe "strikethrough" do
|
39
33
|
|
40
34
|
it "turns strikethrough text to :del: ~~del~~ <del>del</del>" do
|
41
|
-
|
42
|
-
This is my
|
43
|
-
EOF
|
44
|
-
text.to_html.strip.should == <<-EOF.strip
|
45
|
-
This is my <del>old</del> text.
|
46
|
-
EOF
|
35
|
+
Touch_Up.new("This is my ~~old~~ text.").
|
36
|
+
to_html.strip.should == "This is my <del>old</del> text."
|
47
37
|
end # === it "turns strikethrough-ed text to strong: ~~del~~ <del>del</del>" do
|
48
38
|
|
49
39
|
it "leaves surrounding chars alone: I am re~~deleted~~ed." do
|
@@ -56,18 +46,24 @@ end # === describe "strikethrough"
|
|
56
46
|
describe "linking" do
|
57
47
|
|
58
48
|
it "turns text into links: *my link* google.com" do
|
59
|
-
|
60
|
-
|
49
|
+
href="google.com"
|
50
|
+
Touch_Up.new("This is *my link* #{href}.").
|
51
|
+
to_html.should == "This is <a href=\"#{Escape_Escape_Escape.href "http://#{href}"}\">my link</a>."
|
61
52
|
end
|
62
53
|
|
63
54
|
it "turns only text with a period inside to links: text. vs my.text." do
|
64
|
-
|
65
|
-
|
55
|
+
link = "lewrockwell.com"
|
56
|
+
clean = Escape_Escape_Escape.href "http://#{link}"
|
57
|
+
Touch_Up.new(
|
58
|
+
"This is *bold* text. This is my *link* #{link}."
|
59
|
+
).to_html.should ==
|
60
|
+
"This is <strong>bold</strong> text. This is my <a href=\"#{clean}\">link</a>."
|
66
61
|
end
|
67
62
|
|
68
63
|
it "does not create invalid links: javascript://alert('text.text')" do
|
69
|
-
|
70
|
-
|
64
|
+
link = "javascript://alert('text.text')"
|
65
|
+
Touch_Up.new("This is my *link* #{link}.").
|
66
|
+
to_html.should == "This is my <strong>link</strong> #{Escape_Escape_Escape.html link}."
|
71
67
|
end
|
72
68
|
|
73
69
|
it "ignores ending punctuation: .com." do
|
@@ -98,7 +94,7 @@ describe "linking" do
|
|
98
94
|
it "does not auto-link invalid urls: http://www.yahoo.com/&" do
|
99
95
|
txt = "This is invalid: http://кц.рф"
|
100
96
|
Touch_Up.new(txt).
|
101
|
-
to_html.should == txt
|
97
|
+
to_html.should == Escape_Escape_Escape.html(txt)
|
102
98
|
end
|
103
99
|
|
104
100
|
it "does not double-escape hrefs" do
|
@@ -0,0 +1,40 @@
|
|
1
|
+
|
2
|
+
describe 'escaping' do
|
3
|
+
|
4
|
+
it "escapes text" do
|
5
|
+
text = "<strong>text</strong>"
|
6
|
+
actual = Touch_Up.new("#{text} *text*").to_html
|
7
|
+
|
8
|
+
actual.should == "#{Escape_Escape_Escape.html text} <strong>text</strong>"
|
9
|
+
end # === it escapes text
|
10
|
+
|
11
|
+
it "accepts escaped text, w/o double escaping it" do
|
12
|
+
text = "<strong>e</strong>"
|
13
|
+
actual = Touch_Up.new(
|
14
|
+
Escape_Escape_Escape.html "#{text} *text*"
|
15
|
+
).to_html
|
16
|
+
|
17
|
+
actual.should == "#{Escape_Escape_Escape.html text} <strong>text</strong>"
|
18
|
+
end # === it accespts escaped text, w/o double escaping it
|
19
|
+
|
20
|
+
it "escapes :href, not just html" do
|
21
|
+
href = "http://www.example.com/?test='test"
|
22
|
+
e_href = Escape_Escape_Escape.href(href)
|
23
|
+
actual = Touch_Up.new("*my href* #{href}").to_html
|
24
|
+
|
25
|
+
actual.should == %^<a href="#{e_href}">my href</a>^
|
26
|
+
end # === it escapes :href, not just html
|
27
|
+
|
28
|
+
it "escapes content of :a tags" do
|
29
|
+
href = "http://www.example.com/"
|
30
|
+
e_href = Escape_Escape_Escape.href(href)
|
31
|
+
|
32
|
+
text = "my <href>"
|
33
|
+
e_text = Escape_Escape_Escape.html(text)
|
34
|
+
actual = Touch_Up.new("*#{text}* #{href}").to_html
|
35
|
+
|
36
|
+
actual.should == %^<a href="#{e_href}">#{e_text}</a>^
|
37
|
+
end # === it escapes content of :a tags
|
38
|
+
|
39
|
+
end # === describe 'escaping'
|
40
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: touch_up
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- da99
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -109,6 +109,7 @@ files:
|
|
109
109
|
- VERSION
|
110
110
|
- lib/touch_up.rb
|
111
111
|
- specs/0010-it-runs.rb
|
112
|
+
- specs/0011-escaping.rb
|
112
113
|
- specs/lib/helpers.rb
|
113
114
|
- touch_up.gemspec
|
114
115
|
homepage: https://github.com/da99/touch_up
|