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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d9822934b5585190847395099959027911beb2f3
4
- data.tar.gz: f12b3db11d8f4c77e3c48fadfc6a1360895b4f8e
3
+ metadata.gz: 505ccfdec7463152b84a66f2d0c0b6ee4df7d958
4
+ data.tar.gz: 8e04eed0de2037978c2733121d4021f96b6fffb7
5
5
  SHA512:
6
- metadata.gz: 3cdf93d5b4c9bfc7d3343d5b55ca8474955b15f689529db1d639dfba292785db6c99b985c4456ec3c025735344d4ca27b4cc9e5febd70b53825182b95758c5d0
7
- data.tar.gz: c9488f204e20f28cd8e7913a8bbda9b0e912c62fd167c873c6d7b24a7a5b9863c015f28f1a9d3c7fbc06bcd2c446da6f3b1c734eb926b23c3c849ff8c3a85b06
6
+ metadata.gz: d87f017e65610d9c582195716164ecfef7006d4125b1754f0901b269a32f54232fa139c06c6cd1797748222e303f007e32857cdf6b2b3133dc58f4e3a7588acc
7
+ data.tar.gz: 07b29cb1837778b5c54bc18e6345f8202c51366d42f51c6d5436008b2e54da9d79de6a7c5bb601fefe854f0f9c04da936f0abd1b87315b6649ac8d9f6d44b952
@@ -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 = false
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] =~ %r!<(/?)(?:pre|code|kbd|script|style|math)[\s>]!
102
- in_pre = ($1 != "/") # Opening or closing tag?
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('\`', '&#96;')
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(/--/, entity(:em_dash))
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(/---/, entity(:em_dash)).
196
- gsub(/--/, entity(:en_dash))
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(/---/, entity(:en_dash)).
212
- gsub(/--/, entity(:em_dash))
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('...', entity(:ellipsis)).
222
- gsub('. . .', entity(:ellipsis))
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
@@ -1,3 +1,3 @@
1
1
  class RubyPants
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -69,41 +69,51 @@ EOF
69
69
 
70
70
  def test_dashes
71
71
  assert_rp_equal "foo--bar", 'foo&#8212;bar', 1
72
- assert_rp_equal "foo---bar", 'foo&#8212;-bar', 1
73
- assert_rp_equal "foo----bar", 'foo&#8212;&#8212;bar', 1
74
- assert_rp_equal "foo-----bar", 'foo&#8212;&#8212;-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
  '&#8212;foo&#8212;bar&#8212;quux&#8212;', 1
77
76
 
78
77
  assert_rp_equal "foo--bar", 'foo&#8211;bar', 2
79
78
  assert_rp_equal "foo---bar", 'foo&#8212;bar', 2
80
- assert_rp_equal "foo----bar", 'foo&#8212;-bar', 2
81
- assert_rp_equal "foo-----bar", 'foo&#8212;&#8211;bar', 2
79
+ assert_rp_equal "foo----bar", 'foo----bar', 2
82
80
  assert_rp_equal "--foo--bar--quux--",
83
81
  '&#8211;foo&#8211;bar&#8211;quux&#8211;', 2
84
82
 
85
83
  assert_rp_equal "foo--bar", 'foo&#8212;bar', 3
86
84
  assert_rp_equal "foo---bar", 'foo&#8211;bar', 3
87
- assert_rp_equal "foo----bar", 'foo&#8211;-bar', 3
88
- assert_rp_equal "foo-----bar", 'foo&#8211;&#8212;bar', 3
85
+ assert_rp_equal "foo----bar", 'foo----bar', 3
89
86
  assert_rp_equal "--foo--bar--quux--",
90
87
  '&#8212;foo&#8212;bar&#8212;quux&#8212;', 3
88
+ end
91
89
 
92
- # mixed with HTML comments
90
+ def test_html_comments
93
91
  assert_verbatim "<!-- comment -->"
94
92
  assert_verbatim "<!-- <p>foo bar</p> -->"
95
93
  assert_rp_equal "--<!-- -- -->--", '&#8211;<!-- -- -->&#8211;'
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>", '&#8211;<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&#8230;bar'
101
- assert_rp_equal "foo....bar", 'foo&#8230;.bar'
105
+ assert_rp_equal "foo....bar", 'foo....bar'
106
+
107
+ # dots and spaces
108
+ assert_rp_equal "foo. . .bar", 'foo&#8230;bar'
109
+ assert_rp_equal "foo . . . bar", 'foo &#8230; 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&#8230;.bar'
114
+ assert_rp_equal "foo. . ..bar", 'foo. . ..bar'
105
115
  assert_rp_equal "foo. . ...bar", 'foo. . &#8230;bar'
106
- assert_rp_equal "foo. . ....bar", 'foo. . &#8230;.bar'
116
+ assert_rp_equal "foo. . ....bar", 'foo. . ....bar'
107
117
  end
108
118
 
109
119
  def test_backticks
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubypants
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Gruber