rubypants 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rubypants/core.rb +27 -10
- data/lib/rubypants/version.rb +1 -1
- data/test/rubypants_test.rb +21 -11
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 505ccfdec7463152b84a66f2d0c0b6ee4df7d958
|
4
|
+
data.tar.gz: 8e04eed0de2037978c2733121d4021f96b6fffb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d87f017e65610d9c582195716164ecfef7006d4125b1754f0901b269a32f54232fa139c06c6cd1797748222e303f007e32857cdf6b2b3133dc58f4e3a7588acc
|
7
|
+
data.tar.gz: 07b29cb1837778b5c54bc18e6345f8202c51366d42f51c6d5436008b2e54da9d79de6a7c5bb601fefe854f0f9c04da936f0abd1b87315b6649ac8d9f6d44b952
|
data/lib/rubypants/core.rb
CHANGED
@@ -84,7 +84,7 @@ class RubyPants < String
|
|
84
84
|
tokens = tokenize
|
85
85
|
|
86
86
|
# Keep track of when we're inside <pre> or <code> tags.
|
87
|
-
in_pre =
|
87
|
+
in_pre = nil
|
88
88
|
|
89
89
|
# Here is the result stored in.
|
90
90
|
result = ""
|
@@ -98,8 +98,14 @@ class RubyPants < String
|
|
98
98
|
tokens.each do |token|
|
99
99
|
if token.first == :tag
|
100
100
|
result << token[1]
|
101
|
-
if token[1]
|
102
|
-
|
101
|
+
if token[1].end_with? '/>'
|
102
|
+
# ignore self-closing tags
|
103
|
+
elsif token[1] =~ %r!\A<(/?)(pre|code|kbd|script|style|math)[\s>]!
|
104
|
+
if $1 == '' && ! in_pre
|
105
|
+
in_pre = $2
|
106
|
+
elsif $1 == '/' && $2 == in_pre
|
107
|
+
in_pre = nil
|
108
|
+
end
|
103
109
|
end
|
104
110
|
else
|
105
111
|
t = token[1]
|
@@ -178,12 +184,23 @@ class RubyPants < String
|
|
178
184
|
gsub('\`', '`')
|
179
185
|
end
|
180
186
|
|
187
|
+
def self.n_of(n, x)
|
188
|
+
x = Regexp.escape(x)
|
189
|
+
/(?<!#{x}) # not preceded by x
|
190
|
+
#{x}{#{n}} # n of x
|
191
|
+
(?!#{x}) # not followed by x
|
192
|
+
/x
|
193
|
+
end
|
194
|
+
|
195
|
+
DOUBLE_DASH = n_of(2, '-')
|
196
|
+
TRIPLE_DASH = n_of(3, '-')
|
197
|
+
|
181
198
|
# The string, with each instance of "<tt>--</tt>" translated to an
|
182
199
|
# em-dash HTML entity.
|
183
200
|
#
|
184
201
|
def educate_dashes(str)
|
185
202
|
str.
|
186
|
-
gsub(
|
203
|
+
gsub(DOUBLE_DASH, entity(:em_dash))
|
187
204
|
end
|
188
205
|
|
189
206
|
# The string, with each instance of "<tt>--</tt>" translated to an
|
@@ -192,8 +209,8 @@ class RubyPants < String
|
|
192
209
|
#
|
193
210
|
def educate_dashes_oldschool(str)
|
194
211
|
str.
|
195
|
-
gsub(
|
196
|
-
gsub(
|
212
|
+
gsub(TRIPLE_DASH, entity(:em_dash)).
|
213
|
+
gsub(DOUBLE_DASH, entity(:en_dash))
|
197
214
|
end
|
198
215
|
|
199
216
|
# Return the string, with each instance of "<tt>--</tt>" translated
|
@@ -208,8 +225,8 @@ class RubyPants < String
|
|
208
225
|
#
|
209
226
|
def educate_dashes_inverted(str)
|
210
227
|
str.
|
211
|
-
gsub(
|
212
|
-
gsub(
|
228
|
+
gsub(TRIPLE_DASH, entity(:en_dash)).
|
229
|
+
gsub(DOUBLE_DASH, entity(:em_dash))
|
213
230
|
end
|
214
231
|
|
215
232
|
# Return the string, with each instance of "<tt>...</tt>" translated
|
@@ -218,8 +235,8 @@ class RubyPants < String
|
|
218
235
|
#
|
219
236
|
def educate_ellipses(str)
|
220
237
|
str.
|
221
|
-
gsub('
|
222
|
-
gsub(
|
238
|
+
gsub(RubyPants.n_of(3, '.'), entity(:ellipsis)).
|
239
|
+
gsub(/(?<!\.|\. )\. \. \.(?!\.| \.)/, entity(:ellipsis))
|
223
240
|
end
|
224
241
|
|
225
242
|
# Return the string, with "<tt>``backticks''</tt>"-style single quotes
|
data/lib/rubypants/version.rb
CHANGED
data/test/rubypants_test.rb
CHANGED
@@ -69,41 +69,51 @@ EOF
|
|
69
69
|
|
70
70
|
def test_dashes
|
71
71
|
assert_rp_equal "foo--bar", 'foo—bar', 1
|
72
|
-
assert_rp_equal "foo---bar", 'foo
|
73
|
-
assert_rp_equal "foo----bar", 'foo
|
74
|
-
assert_rp_equal "foo-----bar", 'foo——-bar', 1
|
72
|
+
assert_rp_equal "foo---bar", 'foo---bar', 1
|
73
|
+
assert_rp_equal "foo----bar", 'foo----bar', 1
|
75
74
|
assert_rp_equal "--foo--bar--quux--",
|
76
75
|
'—foo—bar—quux—', 1
|
77
76
|
|
78
77
|
assert_rp_equal "foo--bar", 'foo–bar', 2
|
79
78
|
assert_rp_equal "foo---bar", 'foo—bar', 2
|
80
|
-
assert_rp_equal "foo----bar", 'foo
|
81
|
-
assert_rp_equal "foo-----bar", 'foo—–bar', 2
|
79
|
+
assert_rp_equal "foo----bar", 'foo----bar', 2
|
82
80
|
assert_rp_equal "--foo--bar--quux--",
|
83
81
|
'–foo–bar–quux–', 2
|
84
82
|
|
85
83
|
assert_rp_equal "foo--bar", 'foo—bar', 3
|
86
84
|
assert_rp_equal "foo---bar", 'foo–bar', 3
|
87
|
-
assert_rp_equal "foo----bar", 'foo
|
88
|
-
assert_rp_equal "foo-----bar", 'foo–—bar', 3
|
85
|
+
assert_rp_equal "foo----bar", 'foo----bar', 3
|
89
86
|
assert_rp_equal "--foo--bar--quux--",
|
90
87
|
'—foo—bar—quux—', 3
|
88
|
+
end
|
91
89
|
|
92
|
-
|
90
|
+
def test_html_comments
|
93
91
|
assert_verbatim "<!-- comment -->"
|
94
92
|
assert_verbatim "<!-- <p>foo bar</p> -->"
|
95
93
|
assert_rp_equal "--<!-- -- -->--", '–<!-- -- -->–'
|
96
94
|
end
|
97
95
|
|
96
|
+
def test_pre_tags
|
97
|
+
assert_verbatim "<pre>--</pre>"
|
98
|
+
assert_verbatim "<pre><code>--</code>--</pre>"
|
99
|
+
assert_rp_equal "--<pre>--</pre>", '–<pre>--</pre>'
|
100
|
+
end
|
101
|
+
|
98
102
|
def test_ellipses
|
99
103
|
assert_rp_equal "foo..bar", 'foo..bar'
|
100
104
|
assert_rp_equal "foo...bar", 'foo…bar'
|
101
|
-
assert_rp_equal "foo....bar", 'foo
|
105
|
+
assert_rp_equal "foo....bar", 'foo....bar'
|
106
|
+
|
107
|
+
# dots and spaces
|
108
|
+
assert_rp_equal "foo. . .bar", 'foo…bar'
|
109
|
+
assert_rp_equal "foo . . . bar", 'foo … bar'
|
110
|
+
assert_rp_equal "foo. . . .bar", 'foo. . . .bar'
|
111
|
+
assert_rp_equal "foo . . . . bar", 'foo . . . . bar'
|
102
112
|
|
103
113
|
# Nasty ones
|
104
|
-
assert_rp_equal "foo. . ..bar", 'foo
|
114
|
+
assert_rp_equal "foo. . ..bar", 'foo. . ..bar'
|
105
115
|
assert_rp_equal "foo. . ...bar", 'foo. . …bar'
|
106
|
-
assert_rp_equal "foo. . ....bar", 'foo. .
|
116
|
+
assert_rp_equal "foo. . ....bar", 'foo. . ....bar'
|
107
117
|
end
|
108
118
|
|
109
119
|
def test_backticks
|