Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 13
- Log:
Initial import of Typo 2.6.0 sources from a downloaded Tarball.
Typo is a Ruby On Rails based blog engine.
- Author:
- adh
- Date:
- Sat Jul 22 22:25:02 +0100 2006
- Size:
- 48896 Bytes
1 | <?xml version="1.0" encoding="iso-8859-1"?> |
2 | <!DOCTYPE html |
3 | PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
4 | "DTD/xhtml1-transitional.dtd"> |
5 | |
6 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
7 | <head> |
8 | <title>Class: RubyPants</title> |
9 | <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> |
10 | <meta http-equiv="Content-Script-Type" content="text/javascript" /> |
11 | <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" /> |
12 | <script type="text/javascript"> |
13 | // <![CDATA[ |
14 | |
15 | function popupCode( url ) { |
16 | window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400") |
17 | } |
18 | |
19 | function toggleCode( id ) { |
20 | if ( document.getElementById ) |
21 | elem = document.getElementById( id ); |
22 | else if ( document.all ) |
23 | elem = eval( "document.all." + id ); |
24 | else |
25 | return false; |
26 | |
27 | elemStyle = elem.style; |
28 | |
29 | if ( elemStyle.display != "block" ) { |
30 | elemStyle.display = "block" |
31 | } else { |
32 | elemStyle.display = "none" |
33 | } |
34 | |
35 | return true; |
36 | } |
37 | |
38 | // Make codeblocks hidden by default |
39 | document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" ) |
40 | |
41 | // ]]> |
42 | </script> |
43 | |
44 | </head> |
45 | <body> |
46 | |
47 | |
48 | |
49 | <div id="classHeader"> |
50 | <h1>RubyPants <sup class="type-note">(Class)</sup></h1> |
51 | <table class="header-table"> |
52 | <tr class="top-aligned-row"> |
53 | <td><strong>In:</strong></td> |
54 | <td> |
55 | <a href="../files/rubypants_rb.html"> |
56 | rubypants.rb |
57 | </a> |
58 | <br /> |
59 | </td> |
60 | </tr> |
61 | |
62 | <tr class="top-aligned-row"> |
63 | <td><strong>Parent:</strong></td> |
64 | <td> |
65 | String |
66 | </td> |
67 | </tr> |
68 | </table> |
69 | </div> |
70 | <!-- banner header --> |
71 | |
72 | <div id="bodyContent"> |
73 | |
74 | |
75 | <div id="contextContent"> |
76 | |
77 | <div id="description"> |
78 | <h1><a href="RubyPants.html">RubyPants</a> — SmartyPants ported to Ruby</h1> |
79 | <h2>Synopsis</h2> |
80 | <p> |
81 | <a href="RubyPants.html">RubyPants</a> is a Ruby port of the smart-quotes |
82 | library SmartyPants. |
83 | </p> |
84 | <p> |
85 | The original "SmartyPants" is a free web publishing plug-in for |
86 | Movable Type, Blosxom, and BBEdit that easily translates plain ASCII |
87 | punctuation characters into "smart" typographic punctuation HTML |
88 | entities. |
89 | </p> |
90 | <h2>Description</h2> |
91 | <p> |
92 | <a href="RubyPants.html">RubyPants</a> can perform the following |
93 | transformations: |
94 | </p> |
95 | <ul> |
96 | <li>Straight quotes (<tt>"</tt> and <tt>‘</tt>) into |
97 | "curly" quote HTML entities |
98 | |
99 | </li> |
100 | <li>Backticks-style quotes (<tt>``like this’‘</tt>) into |
101 | "curly" quote HTML entities |
102 | |
103 | </li> |
104 | <li>Dashes (<tt>—</tt> and <tt>—</tt>) into en- and em-dash |
105 | entities |
106 | |
107 | </li> |
108 | <li>Three consecutive dots (<tt>…</tt> or <tt>. . .</tt>) into an |
109 | ellipsis entity |
110 | |
111 | </li> |
112 | </ul> |
113 | <p> |
114 | This means you can write, edit, and save your posts using plain old ASCII |
115 | straight quotes, plain dashes, and plain dots, but your published posts |
116 | (and final HTML output) will appear with smart quotes, em-dashes, and |
117 | proper ellipses. |
118 | </p> |
119 | <p> |
120 | <a href="RubyPants.html">RubyPants</a> does not modify characters within |
121 | <tt><pre></tt>, <tt><code></tt>, <tt><kbd></tt>, |
122 | <tt><math></tt> or <tt><script></tt> tag blocks. Typically, |
123 | these tags are used to display text where smart quotes and other |
124 | "smart punctuation" would not be appropriate, such as source code |
125 | or example markup. |
126 | </p> |
127 | <h2>Backslash Escapes</h2> |
128 | <p> |
129 | If you need to use literal straight quotes (or plain hyphens and periods), |
130 | <a href="RubyPants.html">RubyPants</a> accepts the following backslash |
131 | escape sequences to force non-smart punctuation. It does so by transforming |
132 | the escape sequence into a decimal-encoded HTML entity: |
133 | </p> |
134 | <pre> |
135 | \\ \" \' \. \- \` |
136 | </pre> |
137 | <p> |
138 | This is useful, for example, when you want to use straight quotes as foot |
139 | and inch marks: 6’2" tall; a 17" iMac. (Use |
140 | <tt>6\’2\"</tt> resp. <tt>17\"</tt>.) |
141 | </p> |
142 | <h2>Algorithmic Shortcomings</h2> |
143 | <p> |
144 | One situation in which quotes will get curled the wrong way is when |
145 | apostrophes are used at the start of leading contractions. For example: |
146 | </p> |
147 | <pre> |
148 | 'Twas the night before Christmas. |
149 | </pre> |
150 | <p> |
151 | In the case above, <a href="RubyPants.html">RubyPants</a> will turn the |
152 | apostrophe into an opening single-quote, when in fact it should be a |
153 | closing one. I don’t think this problem can be solved in the general |
154 | case—every word processor I’ve tried gets this wrong as well. |
155 | In such cases, it’s best to use the proper HTML entity for closing |
156 | single-quotes ("<tt>&8217;</tt>") by hand. |
157 | </p> |
158 | <h2>Bugs</h2> |
159 | <p> |
160 | To file bug reports or feature requests (except see above) please send |
161 | email to: <a |
162 | href="mailto:chneukirchen@gmail.com">chneukirchen@gmail.com</a> |
163 | </p> |
164 | <p> |
165 | If the bug involves quotes being curled the wrong way, please send example |
166 | text to illustrate. |
167 | </p> |
168 | <h2>Authors</h2> |
169 | <p> |
170 | John Gruber did all of the hard work of writing this software in Perl for |
171 | Movable Type and almost all of this useful documentation. Chad Miller |
172 | ported it to Python to use with Pyblosxom. |
173 | </p> |
174 | <p> |
175 | Christian Neukirchen provided the Ruby port, as a general-purpose library |
176 | that follows the *Cloth API. |
177 | </p> |
178 | <h2>Copyright and License</h2> |
179 | <h3>SmartyPants license:</h3> |
180 | <p> |
181 | Copyright © 2003 John Gruber (<a |
182 | href="http://daringfireball.net">daringfireball.net</a>) All rights |
183 | reserved. |
184 | </p> |
185 | <p> |
186 | Redistribution and use in source and binary forms, with or without |
187 | modification, are permitted provided that the following conditions are met: |
188 | </p> |
189 | <ul> |
190 | <li>Redistributions of source code must retain the above copyright notice, this |
191 | list of conditions and the following disclaimer. |
192 | |
193 | </li> |
194 | <li>Redistributions in binary form must reproduce the above copyright notice, |
195 | this list of conditions and the following disclaimer in the documentation |
196 | and/or other materials provided with the distribution. |
197 | |
198 | </li> |
199 | <li>Neither the name "SmartyPants" nor the names of its contributors |
200 | may be used to endorse or promote products derived from this software |
201 | without specific prior written permission. |
202 | |
203 | </li> |
204 | </ul> |
205 | <p> |
206 | This software is provided by the copyright holders and contributors |
207 | "as is" and any express or implied warranties, including, but not |
208 | limited to, the implied warranties of merchantability and fitness for a |
209 | particular purpose are disclaimed. In no event shall the copyright owner or |
210 | contributors be liable for any direct, indirect, incidental, special, |
211 | exemplary, or consequential damages (including, but not limited to, |
212 | procurement of substitute goods or services; loss of use, data, or profits; |
213 | or business interruption) however caused and on any theory of liability, |
214 | whether in contract, strict liability, or tort (including negligence or |
215 | otherwise) arising in any way out of the use of this software, even if |
216 | advised of the possibility of such damage. |
217 | </p> |
218 | <h3><a href="RubyPants.html">RubyPants</a> license</h3> |
219 | <p> |
220 | <a href="RubyPants.html">RubyPants</a> is a derivative work of SmartyPants |
221 | and smartypants.py. |
222 | </p> |
223 | <p> |
224 | Redistribution and use in source and binary forms, with or without |
225 | modification, are permitted provided that the following conditions are met: |
226 | </p> |
227 | <ul> |
228 | <li>Redistributions of source code must retain the above copyright notice, this |
229 | list of conditions and the following disclaimer. |
230 | |
231 | </li> |
232 | <li>Redistributions in binary form must reproduce the above copyright notice, |
233 | this list of conditions and the following disclaimer in the documentation |
234 | and/or other materials provided with the distribution. |
235 | |
236 | </li> |
237 | </ul> |
238 | <p> |
239 | This software is provided by the copyright holders and contributors |
240 | "as is" and any express or implied warranties, including, but not |
241 | limited to, the implied warranties of merchantability and fitness for a |
242 | particular purpose are disclaimed. In no event shall the copyright owner or |
243 | contributors be liable for any direct, indirect, incidental, special, |
244 | exemplary, or consequential damages (including, but not limited to, |
245 | procurement of substitute goods or services; loss of use, data, or profits; |
246 | or business interruption) however caused and on any theory of liability, |
247 | whether in contract, strict liability, or tort (including negligence or |
248 | otherwise) arising in any way out of the use of this software, even if |
249 | advised of the possibility of such damage. |
250 | </p> |
251 | <h2>Links</h2> |
252 | <table> |
253 | <tr><td valign="top">John Gruber:</td><td><a href="http://daringfireball.net">daringfireball.net</a> |
254 | |
255 | </td></tr> |
256 | <tr><td valign="top">SmartyPants:</td><td><a |
257 | href="http://daringfireball.net/projects/smartypants">daringfireball.net/projects/smartypants</a> |
258 | |
259 | </td></tr> |
260 | <tr><td valign="top">Chad Miller:</td><td><a href="http://web.chad.org">web.chad.org</a> |
261 | |
262 | </td></tr> |
263 | <tr><td valign="top">Christian Neukirchen:</td><td><a href="http://kronavita.de/chris">kronavita.de/chris</a> |
264 | |
265 | </td></tr> |
266 | </table> |
267 | |
268 | </div> |
269 | |
270 | |
271 | <div id="method-list"> |
272 | <h2 class="section-bar">Methods</h2> |
273 | |
274 | <div class="name-list"> |
275 | <a href="#M000008">educate_backticks</a> |
276 | <a href="#M000004">educate_dashes</a> |
277 | <a href="#M000006">educate_dashes_inverted</a> |
278 | <a href="#M000005">educate_dashes_oldschool</a> |
279 | <a href="#M000007">educate_ellipses</a> |
280 | <a href="#M000010">educate_quotes</a> |
281 | <a href="#M000009">educate_single_backticks</a> |
282 | <a href="#M000001">new</a> |
283 | <a href="#M000003">process_escapes</a> |
284 | <a href="#M000011">stupefy_entities</a> |
285 | <a href="#M000002">to_html</a> |
286 | <a href="#M000012">tokenize</a> |
287 | </div> |
288 | </div> |
289 | |
290 | <div id="constants-list"> |
291 | <h2 class="section-bar">Constants</h2> |
292 | |
293 | <div class="name-list"> |
294 | <table summary="Constants"> |
295 | <tr class="top-aligned-row context-row"> |
296 | <td class="context-item-name">VERSION</td> |
297 | <td>=</td> |
298 | <td class="context-item-value">"0.2"</td> |
299 | </tr> |
300 | </table> |
301 | </div> |
302 | </div> |
303 | |
304 | |
305 | |
306 | |
307 | |
308 | </div> |
309 | |
310 | |
311 | |
312 | <!-- if includes --> |
313 | |
314 | |
315 | <!-- if method_list --> |
316 | <div id="methods"> |
317 | <h2 class="section-bar">Public Class methods</h2> |
318 | |
319 | <div id="method-M000001" class="method-detail"> |
320 | <a name="M000001"></a> |
321 | |
322 | <div class="method-heading"> |
323 | <a href="#M000001" class="method-signature"> |
324 | <span class="method-name">new</span><span class="method-args">(string, options=[2])</span> |
325 | </a> |
326 | </div> |
327 | |
328 | <div class="method-description"> |
329 | <p> |
330 | Create a new <a href="RubyPants.html">RubyPants</a> instance with the text |
331 | in <tt>string</tt>. |
332 | </p> |
333 | <p> |
334 | Allowed elements in the options array: |
335 | </p> |
336 | <table> |
337 | <tr><td valign="top">0 :</td><td>do nothing |
338 | |
339 | </td></tr> |
340 | <tr><td valign="top">1 :</td><td>enable all, using only em-dash shortcuts |
341 | |
342 | </td></tr> |
343 | <tr><td valign="top">2 :</td><td>enable all, using old school en- and em-dash shortcuts (<b>default</b>) |
344 | |
345 | </td></tr> |
346 | <tr><td valign="top">3 :</td><td>enable all, using inverted old school en and em-dash shortcuts |
347 | |
348 | </td></tr> |
349 | <tr><td valign="top">-1 :</td><td>stupefy (translate HTML entities to their ASCII-counterparts) |
350 | |
351 | </td></tr> |
352 | </table> |
353 | <p> |
354 | If you don’t like any of these defaults, you can pass symbols to |
355 | change <a href="RubyPants.html">RubyPants</a>’ behavior: |
356 | </p> |
357 | <table> |
358 | <tr><td valign="top"><tt>:quotes</tt> :</td><td>quotes |
359 | |
360 | </td></tr> |
361 | <tr><td valign="top"><tt>:backticks</tt> :</td><td>backtick quotes (``double’’ only) |
362 | |
363 | </td></tr> |
364 | <tr><td valign="top"><tt>:allbackticks</tt> :</td><td>backtick quotes (``double’’ and `single’) |
365 | |
366 | </td></tr> |
367 | <tr><td valign="top"><tt>:dashes</tt> :</td><td>dashes |
368 | |
369 | </td></tr> |
370 | <tr><td valign="top"><tt>:oldschool</tt> :</td><td>old school dashes |
371 | |
372 | </td></tr> |
373 | <tr><td valign="top"><tt>:inverted</tt> :</td><td>inverted old school dashes |
374 | |
375 | </td></tr> |
376 | <tr><td valign="top"><tt>:ellipses</tt> :</td><td>ellipses |
377 | |
378 | </td></tr> |
379 | <tr><td valign="top"><tt>:convertquotes</tt> :</td><td>convert <tt>&quot;</tt> entities to <tt>"</tt> for Dreamweaver |
380 | users |
381 | |
382 | </td></tr> |
383 | <tr><td valign="top"><tt>:stupefy</tt> :</td><td>translate <a href="RubyPants.html">RubyPants</a> HTML entities to their |
384 | ASCII counterparts. |
385 | |
386 | </td></tr> |
387 | </table> |
388 | <p><a class="source-toggle" href="#" |
389 | onclick="toggleCode('M000001-source');return false;">[Source]</a></p> |
390 | <div class="method-source-code" id="M000001-source"> |
391 | <pre> |
392 | <span class="ruby-comment cmt"># File rubypants.rb, line 207</span> |
393 | 207: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">string</span>, <span class="ruby-identifier">options</span>=[<span class="ruby-value">2</span>]) |
394 | 208: <span class="ruby-keyword kw">super</span> <span class="ruby-identifier">string</span> |
395 | 209: <span class="ruby-ivar">@options</span> = [<span class="ruby-operator">*</span><span class="ruby-identifier">options</span>] |
396 | 210: <span class="ruby-keyword kw">end</span> |
397 | </pre> |
398 | </div> |
399 | </div> |
400 | </div> |
401 | |
402 | <h2 class="section-bar">Public Instance methods</h2> |
403 | |
404 | <div id="method-M000002" class="method-detail"> |
405 | <a name="M000002"></a> |
406 | |
407 | <div class="method-heading"> |
408 | <a href="#M000002" class="method-signature"> |
409 | <span class="method-name">to_html</span><span class="method-args">()</span> |
410 | </a> |
411 | </div> |
412 | |
413 | <div class="method-description"> |
414 | <p> |
415 | Apply SmartyPants transformations. |
416 | </p> |
417 | <p><a class="source-toggle" href="#" |
418 | onclick="toggleCode('M000002-source');return false;">[Source]</a></p> |
419 | <div class="method-source-code" id="M000002-source"> |
420 | <pre> |
421 | <span class="ruby-comment cmt"># File rubypants.rb, line 213</span> |
422 | 213: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_html</span> |
423 | 214: <span class="ruby-identifier">do_quotes</span> = <span class="ruby-identifier">do_backticks</span> = <span class="ruby-identifier">do_dashes</span> = <span class="ruby-identifier">do_ellipses</span> = <span class="ruby-identifier">do_stupify</span> = <span class="ruby-keyword kw">nil</span> |
424 | 215: <span class="ruby-identifier">convert_quotes</span> = <span class="ruby-keyword kw">false</span> |
425 | 216: |
426 | 217: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">include?</span> <span class="ruby-value">0</span> |
427 | 218: <span class="ruby-comment cmt"># Do nothing.</span> |
428 | 219: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span> |
429 | 220: <span class="ruby-keyword kw">elsif</span> <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">include?</span> <span class="ruby-value">1</span> |
430 | 221: <span class="ruby-comment cmt"># Do everything, turn all options on.</span> |
431 | 222: <span class="ruby-identifier">do_quotes</span> = <span class="ruby-identifier">do_backticks</span> = <span class="ruby-identifier">do_ellipses</span> = <span class="ruby-keyword kw">true</span> |
432 | 223: <span class="ruby-identifier">do_dashes</span> = <span class="ruby-identifier">:normal</span> |
433 | 224: <span class="ruby-keyword kw">elsif</span> <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">include?</span> <span class="ruby-value">2</span> |
434 | 225: <span class="ruby-comment cmt"># Do everything, turn all options on, use old school dash shorthand.</span> |
435 | 226: <span class="ruby-identifier">do_quotes</span> = <span class="ruby-identifier">do_backticks</span> = <span class="ruby-identifier">do_ellipses</span> = <span class="ruby-keyword kw">true</span> |
436 | 227: <span class="ruby-identifier">do_dashes</span> = <span class="ruby-identifier">:oldschool</span> |
437 | 228: <span class="ruby-keyword kw">elsif</span> <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">include?</span> <span class="ruby-value">3</span> |
438 | 229: <span class="ruby-comment cmt"># Do everything, turn all options on, use inverted old school</span> |
439 | 230: <span class="ruby-comment cmt"># dash shorthand.</span> |
440 | 231: <span class="ruby-identifier">do_quotes</span> = <span class="ruby-identifier">do_backticks</span> = <span class="ruby-identifier">do_ellipses</span> = <span class="ruby-keyword kw">true</span> |
441 | 232: <span class="ruby-identifier">do_dashes</span> = <span class="ruby-identifier">:inverted</span> |
442 | 233: <span class="ruby-keyword kw">elsif</span> <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-value">-1</span>) |
443 | 234: <span class="ruby-identifier">do_stupefy</span> = <span class="ruby-keyword kw">true</span> |
444 | 235: <span class="ruby-keyword kw">else</span> |
445 | 236: <span class="ruby-identifier">do_quotes</span> = <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">include?</span> <span class="ruby-identifier">:quotes</span> |
446 | 237: <span class="ruby-identifier">do_backticks</span> = <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">include?</span> <span class="ruby-identifier">:backticks</span> |
447 | 238: <span class="ruby-identifier">do_backticks</span> = <span class="ruby-identifier">:both</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">include?</span> <span class="ruby-identifier">:allbackticks</span> |
448 | 239: <span class="ruby-identifier">do_dashes</span> = <span class="ruby-identifier">:normal</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">include?</span> <span class="ruby-identifier">:dashes</span> |
449 | 240: <span class="ruby-identifier">do_dashes</span> = <span class="ruby-identifier">:oldschool</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">include?</span> <span class="ruby-identifier">:oldschool</span> |
450 | 241: <span class="ruby-identifier">do_dashes</span> = <span class="ruby-identifier">:inverted</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">include?</span> <span class="ruby-identifier">:inverted</span> |
451 | 242: <span class="ruby-identifier">do_ellipses</span> = <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">include?</span> <span class="ruby-identifier">:ellipses</span> |
452 | 243: <span class="ruby-identifier">convert_quotes</span> = <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">include?</span> <span class="ruby-identifier">:convertquotes</span> |
453 | 244: <span class="ruby-identifier">do_stupefy</span> = <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">include?</span> <span class="ruby-identifier">:stupefy</span> |
454 | 245: <span class="ruby-keyword kw">end</span> |
455 | 246: |
456 | 247: <span class="ruby-comment cmt"># Parse the HTML</span> |
457 | 248: <span class="ruby-identifier">tokens</span> = <span class="ruby-identifier">tokenize</span> |
458 | 249: |
459 | 250: <span class="ruby-comment cmt"># Keep track of when we're inside <pre> or <code> tags.</span> |
460 | 251: <span class="ruby-identifier">in_pre</span> = <span class="ruby-keyword kw">false</span> |
461 | 252: |
462 | 253: <span class="ruby-comment cmt"># Here is the result stored in.</span> |
463 | 254: <span class="ruby-identifier">result</span> = <span class="ruby-value str">""</span> |
464 | 255: |
465 | 256: <span class="ruby-comment cmt"># This is a cheat, used to get some context for one-character</span> |
466 | 257: <span class="ruby-comment cmt"># tokens that consist of just a quote char. What we do is remember</span> |
467 | 258: <span class="ruby-comment cmt"># the last character of the previous text token, to use as context</span> |
468 | 259: <span class="ruby-comment cmt"># to curl single- character quote tokens correctly.</span> |
469 | 260: <span class="ruby-identifier">prev_token_last_char</span> = <span class="ruby-keyword kw">nil</span> |
470 | 261: |
471 | 262: <span class="ruby-identifier">tokens</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">token</span><span class="ruby-operator">|</span> |
472 | 263: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">token</span>.<span class="ruby-identifier">first</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:tag</span> |
473 | 264: <span class="ruby-identifier">result</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">token</span>[<span class="ruby-value">1</span>] |
474 | 265: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">token</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">=~</span> <span class="ruby-regexp re">%!<(/?)(?:pre|code|kbd|script|math)[\s>]!</span> |
475 | 266: <span class="ruby-identifier">in_pre</span> = (<span class="ruby-identifier">$1</span> <span class="ruby-operator">!=</span> <span class="ruby-value str">"/"</span>) <span class="ruby-comment cmt"># Opening or closing tag?</span> |
476 | 267: <span class="ruby-keyword kw">end</span> |
477 | 268: <span class="ruby-keyword kw">else</span> |
478 | 269: <span class="ruby-identifier">t</span> = <span class="ruby-identifier">token</span>[<span class="ruby-value">1</span>] |
479 | 270: |
480 | 271: <span class="ruby-comment cmt"># Remember last char of this token before processing.</span> |
481 | 272: <span class="ruby-identifier">last_char</span> = <span class="ruby-identifier">t</span>[<span class="ruby-value">-1</span>].<span class="ruby-identifier">chr</span> |
482 | 273: |
483 | 274: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">in_pre</span> |
484 | 275: <span class="ruby-identifier">t</span> = <span class="ruby-identifier">process_escapes</span> <span class="ruby-identifier">t</span> |
485 | 276: |
486 | 277: <span class="ruby-identifier">t</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/&quot;/</span>, <span class="ruby-value str">'"'</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">convert_quotes</span> |
487 | 278: |
488 | 279: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">do_dashes</span> |
489 | 280: <span class="ruby-identifier">t</span> = <span class="ruby-identifier">educate_dashes</span> <span class="ruby-identifier">t</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">do_dashes</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:normal</span> |
490 | 281: <span class="ruby-identifier">t</span> = <span class="ruby-identifier">educate_dashes_oldschool</span> <span class="ruby-identifier">t</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">do_dashes</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:oldschool</span> |
491 | 282: <span class="ruby-identifier">t</span> = <span class="ruby-identifier">educate_dashes_inverted</span> <span class="ruby-identifier">t</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">do_dashes</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:inverted</span> |
492 | 283: <span class="ruby-keyword kw">end</span> |
493 | 284: |
494 | 285: <span class="ruby-identifier">t</span> = <span class="ruby-identifier">educate_ellipses</span> <span class="ruby-identifier">t</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">do_ellipses</span> |
495 | 286: |
496 | 287: <span class="ruby-comment cmt"># Note: backticks need to be processed before quotes.</span> |
497 | 288: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">do_backticks</span> |
498 | 289: <span class="ruby-identifier">t</span> = <span class="ruby-identifier">educate_backticks</span> <span class="ruby-identifier">t</span> |
499 | 290: <span class="ruby-identifier">t</span> = <span class="ruby-identifier">educate_single_backticks</span> <span class="ruby-identifier">t</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">do_backticks</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:both</span> |
500 | 291: <span class="ruby-keyword kw">end</span> |
501 | 292: |
502 | 293: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">do_quotes</span> |
503 | 294: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">t</span> <span class="ruby-operator">==</span> <span class="ruby-value str">"'"</span> |
504 | 295: <span class="ruby-comment cmt"># Special case: single-character ' token</span> |
505 | 296: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">prev_token_last_char</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/\S/</span> |
506 | 297: <span class="ruby-identifier">t</span> = <span class="ruby-value str">"&#8217;"</span> |
507 | 298: <span class="ruby-keyword kw">else</span> |
508 | 299: <span class="ruby-identifier">t</span> = <span class="ruby-value str">"&#8216;"</span> |
509 | 300: <span class="ruby-keyword kw">end</span> |
510 | 301: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">t</span> <span class="ruby-operator">==</span> <span class="ruby-value str">'"'</span> |
511 | 302: <span class="ruby-comment cmt"># Special case: single-character " token</span> |
512 | 303: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">prev_token_last_char</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/\S/</span> |
513 | 304: <span class="ruby-identifier">t</span> = <span class="ruby-value str">"&#8221;"</span> |
514 | 305: <span class="ruby-keyword kw">else</span> |
515 | 306: <span class="ruby-identifier">t</span> = <span class="ruby-value str">"&#8220;"</span> |
516 | 307: <span class="ruby-keyword kw">end</span> |
517 | 308: <span class="ruby-keyword kw">else</span> |
518 | 309: <span class="ruby-comment cmt"># Normal case: </span> |
519 | 310: <span class="ruby-identifier">t</span> = <span class="ruby-identifier">educate_quotes</span> <span class="ruby-identifier">t</span> |
520 | 311: <span class="ruby-keyword kw">end</span> |
521 | 312: <span class="ruby-keyword kw">end</span> |
522 | 313: |
523 | 314: <span class="ruby-identifier">t</span> = <span class="ruby-identifier">stupefy_entities</span> <span class="ruby-identifier">t</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">do_stupefy</span> |
524 | 315: <span class="ruby-keyword kw">end</span> |
525 | 316: |
526 | 317: <span class="ruby-identifier">prev_token_last_char</span> = <span class="ruby-identifier">last_char</span> |
527 | 318: <span class="ruby-identifier">result</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">t</span> |
528 | 319: <span class="ruby-keyword kw">end</span> |
529 | 320: } |
530 | 321: |
531 | 322: <span class="ruby-comment cmt"># Done</span> |
532 | 323: <span class="ruby-identifier">result</span> |
533 | 324: <span class="ruby-keyword kw">end</span> |
534 | </pre> |
535 | </div> |
536 | </div> |
537 | </div> |
538 | |
539 | <h2 class="section-bar">Protected Instance methods</h2> |
540 | |
541 | <div id="method-M000008" class="method-detail"> |
542 | <a name="M000008"></a> |
543 | |
544 | <div class="method-heading"> |
545 | <a href="#M000008" class="method-signature"> |
546 | <span class="method-name">educate_backticks</span><span class="method-args">(str)</span> |
547 | </a> |
548 | </div> |
549 | |
550 | <div class="method-description"> |
551 | <p> |
552 | Return the string, with |
553 | "<tt>``backticks’‘</tt>"-style single quotes |
554 | translated into HTML curly quote entities. |
555 | </p> |
556 | <p><a class="source-toggle" href="#" |
557 | onclick="toggleCode('M000008-source');return false;">[Source]</a></p> |
558 | <div class="method-source-code" id="M000008-source"> |
559 | <pre> |
560 | <span class="ruby-comment cmt"># File rubypants.rb, line 384</span> |
561 | 384: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">educate_backticks</span>(<span class="ruby-identifier">str</span>) |
562 | 385: <span class="ruby-identifier">str</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-value str">"``"</span>, <span class="ruby-value str">'&#8220;'</span>).<span class="ruby-identifier">gsub</span>(<span class="ruby-value str">"''"</span>, <span class="ruby-value str">'&#8221;'</span>) |
563 | 386: <span class="ruby-keyword kw">end</span> |
564 | </pre> |
565 | </div> |
566 | </div> |
567 | </div> |
568 | |
569 | <div id="method-M000004" class="method-detail"> |
570 | <a name="M000004"></a> |
571 | |
572 | <div class="method-heading"> |
573 | <a href="#M000004" class="method-signature"> |
574 | <span class="method-name">educate_dashes</span><span class="method-args">(str)</span> |
575 | </a> |
576 | </div> |
577 | |
578 | <div class="method-description"> |
579 | <p> |
580 | The string, with each instance of "<tt>—</tt>" translated |
581 | to an em-dash HTML entity. |
582 | </p> |
583 | <p><a class="source-toggle" href="#" |
584 | onclick="toggleCode('M000004-source');return false;">[Source]</a></p> |
585 | <div class="method-source-code" id="M000004-source"> |
586 | <pre> |
587 | <span class="ruby-comment cmt"># File rubypants.rb, line 347</span> |
588 | 347: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">educate_dashes</span>(<span class="ruby-identifier">str</span>) |
589 | 348: <span class="ruby-identifier">str</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/--/</span>, <span class="ruby-value str">'&#8212;'</span>) |
590 | 349: <span class="ruby-keyword kw">end</span> |
591 | </pre> |
592 | </div> |
593 | </div> |
594 | </div> |
595 | |
596 | <div id="method-M000006" class="method-detail"> |
597 | <a name="M000006"></a> |
598 | |
599 | <div class="method-heading"> |
600 | <a href="#M000006" class="method-signature"> |
601 | <span class="method-name">educate_dashes_inverted</span><span class="method-args">(str)</span> |
602 | </a> |
603 | </div> |
604 | |
605 | <div class="method-description"> |
606 | <p> |
607 | Return the string, with each instance of "<tt>—</tt>" |
608 | translated to an em-dash HTML entity, and each "<tt>—</tt>" |
609 | translated to an en-dash HTML entity. Two reasons why: First, unlike the |
610 | en- and em-dash syntax supported by <tt><a |
611 | href="RubyPants.html#M000005">educate_dashes_oldschool</a></tt>, it’s |
612 | compatible with existing entries written before SmartyPants 1.1, back when |
613 | "<tt>—</tt>" was only used for em-dashes. Second, em-dashes |
614 | are more common than en-dashes, and so it sort of makes sense that the |
615 | shortcut should be shorter to type. (Thanks to Aaron Swartz for the idea.) |
616 | </p> |
617 | <p><a class="source-toggle" href="#" |
618 | onclick="toggleCode('M000006-source');return false;">[Source]</a></p> |
619 | <div class="method-source-code" id="M000006-source"> |
620 | <pre> |
621 | <span class="ruby-comment cmt"># File rubypants.rb, line 369</span> |
622 | 369: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">educate_dashes_inverted</span>(<span class="ruby-identifier">str</span>) |
623 | 370: <span class="ruby-identifier">str</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/---/</span>, <span class="ruby-value str">'&#8211;'</span>).<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/--/</span>, <span class="ruby-value str">'&#8212;'</span>) |
624 | 371: <span class="ruby-keyword kw">end</span> |
625 | </pre> |
626 | </div> |
627 | </div> |
628 | </div> |
629 | |
630 | <div id="method-M000005" class="method-detail"> |
631 | <a name="M000005"></a> |
632 | |
633 | <div class="method-heading"> |
634 | <a href="#M000005" class="method-signature"> |
635 | <span class="method-name">educate_dashes_oldschool</span><span class="method-args">(str)</span> |
636 | </a> |
637 | </div> |
638 | |
639 | <div class="method-description"> |
640 | <p> |
641 | The string, with each instance of "<tt>—</tt>" translated |
642 | to an en-dash HTML entity, and each "<tt>—</tt>" translated |
643 | to an em-dash HTML entity. |
644 | </p> |
645 | <p><a class="source-toggle" href="#" |
646 | onclick="toggleCode('M000005-source');return false;">[Source]</a></p> |
647 | <div class="method-source-code" id="M000005-source"> |
648 | <pre> |
649 | <span class="ruby-comment cmt"># File rubypants.rb, line 355</span> |
650 | 355: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">educate_dashes_oldschool</span>(<span class="ruby-identifier">str</span>) |
651 | 356: <span class="ruby-identifier">str</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/---/</span>, <span class="ruby-value str">'&#8212;'</span>).<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/--/</span>, <span class="ruby-value str">'&#8211;'</span>) |
652 | 357: <span class="ruby-keyword kw">end</span> |
653 | </pre> |
654 | </div> |
655 | </div> |
656 | </div> |
657 | |
658 | <div id="method-M000007" class="method-detail"> |
659 | <a name="M000007"></a> |
660 | |
661 | <div class="method-heading"> |
662 | <a href="#M000007" class="method-signature"> |
663 | <span class="method-name">educate_ellipses</span><span class="method-args">(str)</span> |
664 | </a> |
665 | </div> |
666 | |
667 | <div class="method-description"> |
668 | <p> |
669 | Return the string, with each instance of "<tt>…</tt>" |
670 | translated to an ellipsis HTML entity. Also converts the case where there |
671 | are spaces between the dots. |
672 | </p> |
673 | <p><a class="source-toggle" href="#" |
674 | onclick="toggleCode('M000007-source');return false;">[Source]</a></p> |
675 | <div class="method-source-code" id="M000007-source"> |
676 | <pre> |
677 | <span class="ruby-comment cmt"># File rubypants.rb, line 377</span> |
678 | 377: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">educate_ellipses</span>(<span class="ruby-identifier">str</span>) |
679 | 378: <span class="ruby-identifier">str</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-value str">'...'</span>, <span class="ruby-value str">'&#8230;'</span>).<span class="ruby-identifier">gsub</span>(<span class="ruby-value str">'. . .'</span>, <span class="ruby-value str">'&#8230;'</span>) |
680 | 379: <span class="ruby-keyword kw">end</span> |
681 | </pre> |
682 | </div> |
683 | </div> |
684 | </div> |
685 | |
686 | <div id="method-M000010" class="method-detail"> |
687 | <a name="M000010"></a> |
688 | |
689 | <div class="method-heading"> |
690 | <a href="#M000010" class="method-signature"> |
691 | <span class="method-name">educate_quotes</span><span class="method-args">(str)</span> |
692 | </a> |
693 | </div> |
694 | |
695 | <div class="method-description"> |
696 | <p> |
697 | Return the string, with "educated" curly quote HTML entities. |
698 | </p> |
699 | <p><a class="source-toggle" href="#" |
700 | onclick="toggleCode('M000010-source');return false;">[Source]</a></p> |
701 | <div class="method-source-code" id="M000010-source"> |
702 | <pre> |
703 | <span class="ruby-comment cmt"># File rubypants.rb, line 397</span> |
704 | 397: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">educate_quotes</span>(<span class="ruby-identifier">str</span>) |
705 | 398: <span class="ruby-identifier">punct_class</span> = <span class="ruby-value str">'[!"#\$\%\'()*+,\-.\/:;<=>?\@\[\\\\\]\^^_`{|}~]'</span> |
706 | 399: |
707 | 400: <span class="ruby-identifier">str</span> = <span class="ruby-identifier">str</span>.<span class="ruby-identifier">dup</span> |
708 | 401: |
709 | 402: <span class="ruby-comment cmt"># Special case if the very first character is a quote followed by</span> |
710 | 403: <span class="ruby-comment cmt"># punctuation at a non-word-break. Close the quotes by brute</span> |
711 | 404: <span class="ruby-comment cmt"># force:</span> |
712 | 405: <span class="ruby-identifier">str</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-node">/^'(?=#{punct_class}\B)/</span>, <span class="ruby-value str">'&#8217;'</span>) |
713 | 406: <span class="ruby-identifier">str</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-node">/^"(?=#{punct_class}\B)/</span>, <span class="ruby-value str">'&#8221;'</span>) |
714 | 407: |
715 | 408: <span class="ruby-comment cmt"># Special case for double sets of quotes, e.g.:</span> |
716 | 409: <span class="ruby-comment cmt"># <p>He said, "'Quoted' words in a larger quote."</p></span> |
717 | 410: <span class="ruby-identifier">str</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/"'(?=\w)/</span>, <span class="ruby-value str">'&#8220;&#8216;'</span>) |
718 | 411: <span class="ruby-identifier">str</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/'"(?=\w)/</span>, <span class="ruby-value str">'&#8216;&#8220;'</span>) |
719 | 412: |
720 | 413: <span class="ruby-comment cmt"># Special case for decade abbreviations (the '80s):</span> |
721 | 414: <span class="ruby-identifier">str</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/'(?=\d\ds)/</span>, <span class="ruby-value str">'&#8217;'</span>) |
722 | 415: |
723 | 416: <span class="ruby-identifier">close_class</span> = <span class="ruby-value str">%![^\ \t\r\n\\[\{\(\-]!</span> |
724 | 417: <span class="ruby-identifier">dec_dashes</span> = <span class="ruby-value str">'&#8211;|&#8212;'</span> |
725 | 418: |
726 | 419: <span class="ruby-comment cmt"># Get most opening single quotes:</span> |
727 | 420: <span class="ruby-identifier">str</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-node">/(\s|&nbsp;|--|&[mn]dash;|#{dec_dashes}|&#x201[34];)'(?=\w)/</span>, |
728 | 421: <span class="ruby-value str">'\1&#8216;'</span>) |
729 | 422: <span class="ruby-comment cmt"># Single closing quotes:</span> |
730 | 423: <span class="ruby-identifier">str</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-node">/(#{close_class})'/</span>, <span class="ruby-value str">'\1&#8217;'</span>) |
731 | 424: <span class="ruby-identifier">str</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/'(\s|s\b|$)/</span>, <span class="ruby-value str">'&#8217;\1'</span>) |
732 | 425: <span class="ruby-comment cmt"># Any remaining single quotes should be opening ones:</span> |
733 | 426: <span class="ruby-identifier">str</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/'/</span>, <span class="ruby-value str">'&#8216;'</span>) |
734 | 427: |
735 | 428: <span class="ruby-comment cmt"># Get most opening double quotes:</span> |
736 | 429: <span class="ruby-identifier">str</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-node">/(\s|&nbsp;|--|&[mn]dash;|#{dec_dashes}|&#x201[34];)"(?=\w)/</span>, |
737 | 430: <span class="ruby-value str">'\1&#8220;'</span>) |
738 | 431: <span class="ruby-comment cmt"># Double closing quotes:</span> |
739 | 432: <span class="ruby-identifier">str</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-node">/(#{close_class})"/</span>, <span class="ruby-value str">'\1&#8221;'</span>) |
740 | 433: <span class="ruby-identifier">str</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/"(\s|s\b|$)/</span>, <span class="ruby-value str">'&#8221;\1'</span>) |
741 | 434: <span class="ruby-comment cmt"># Any remaining quotes should be opening ones:</span> |
742 | 435: <span class="ruby-identifier">str</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/"/</span>, <span class="ruby-value str">'&#8220;'</span>) |
743 | 436: |
744 | 437: <span class="ruby-identifier">str</span> |
745 | 438: <span class="ruby-keyword kw">end</span> |
746 | </pre> |
747 | </div> |
748 | </div> |
749 | </div> |
750 | |
751 | <div id="method-M000009" class="method-detail"> |
752 | <a name="M000009"></a> |
753 | |
754 | <div class="method-heading"> |
755 | <a href="#M000009" class="method-signature"> |
756 | <span class="method-name">educate_single_backticks</span><span class="method-args">(str)</span> |
757 | </a> |
758 | </div> |
759 | |
760 | <div class="method-description"> |
761 | <p> |
762 | Return the string, with "<tt>`backticks’</tt>"-style single |
763 | quotes translated into HTML curly quote entities. |
764 | </p> |
765 | <p><a class="source-toggle" href="#" |
766 | onclick="toggleCode('M000009-source');return false;">[Source]</a></p> |
767 | <div class="method-source-code" id="M000009-source"> |
768 | <pre> |
769 | <span class="ruby-comment cmt"># File rubypants.rb, line 391</span> |
770 | 391: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">educate_single_backticks</span>(<span class="ruby-identifier">str</span>) |
771 | 392: <span class="ruby-identifier">str</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-value str">"`"</span>, <span class="ruby-value str">'&#8216;'</span>).<span class="ruby-identifier">gsub</span>(<span class="ruby-value str">"'"</span>, <span class="ruby-value str">'&#8217;'</span>) |
772 | 393: <span class="ruby-keyword kw">end</span> |
773 | </pre> |
774 | </div> |
775 | </div> |
776 | </div> |
777 | |
778 | <div id="method-M000003" class="method-detail"> |
779 | <a name="M000003"></a> |
780 | |
781 | <div class="method-heading"> |
782 | <a href="#M000003" class="method-signature"> |
783 | <span class="method-name">process_escapes</span><span class="method-args">(str)</span> |
784 | </a> |
785 | </div> |
786 | |
787 | <div class="method-description"> |
788 | <p> |
789 | Return the string, with after processing the following backslash escape |
790 | sequences. This is useful if you want to force a "dumb" quote or |
791 | other character to appear. |
792 | </p> |
793 | <p> |
794 | Escaped are: |
795 | </p> |
796 | <pre> |
797 | \\ \" \' \. \- \` |
798 | </pre> |
799 | <p><a class="source-toggle" href="#" |
800 | onclick="toggleCode('M000003-source');return false;">[Source]</a></p> |
801 | <div class="method-source-code" id="M000003-source"> |
802 | <pre> |
803 | <span class="ruby-comment cmt"># File rubypants.rb, line 335</span> |
804 | 335: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">process_escapes</span>(<span class="ruby-identifier">str</span>) |
805 | 336: <span class="ruby-identifier">str</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-value str">'\\\\'</span>, <span class="ruby-value str">'&#92;'</span>). |
806 | 337: <span class="ruby-identifier">gsub</span>(<span class="ruby-value str">'\"'</span>, <span class="ruby-value str">'&#34;'</span>). |
807 | 338: <span class="ruby-identifier">gsub</span>(<span class="ruby-value str">"\\\'"</span>, <span class="ruby-value str">'&#39;'</span>). |
808 | 339: <span class="ruby-identifier">gsub</span>(<span class="ruby-value str">'\.'</span>, <span class="ruby-value str">'&#46;'</span>). |
809 | 340: <span class="ruby-identifier">gsub</span>(<span class="ruby-value str">'\-'</span>, <span class="ruby-value str">'&#45;'</span>). |
810 | 341: <span class="ruby-identifier">gsub</span>(<span class="ruby-value str">'\`'</span>, <span class="ruby-value str">'&#96;'</span>) |
811 | 342: <span class="ruby-keyword kw">end</span> |
812 | </pre> |
813 | </div> |
814 | </div> |
815 | </div> |
816 | |
817 | <div id="method-M000011" class="method-detail"> |
818 | <a name="M000011"></a> |
819 | |
820 | <div class="method-heading"> |
821 | <a href="#M000011" class="method-signature"> |
822 | <span class="method-name">stupefy_entities</span><span class="method-args">(str)</span> |
823 | </a> |
824 | </div> |
825 | |
826 | <div class="method-description"> |
827 | <p> |
828 | Return the string, with each <a href="RubyPants.html">RubyPants</a> HTML |
829 | entity translated to its ASCII counterpart. |
830 | </p> |
831 | <p> |
832 | Note: This is not reversible (but exactly the same as in SmartyPants) |
833 | </p> |
834 | <p><a class="source-toggle" href="#" |
835 | onclick="toggleCode('M000011-source');return false;">[Source]</a></p> |
836 | <div class="method-source-code" id="M000011-source"> |
837 | <pre> |
838 | <span class="ruby-comment cmt"># File rubypants.rb, line 445</span> |
839 | 445: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">stupefy_entities</span>(<span class="ruby-identifier">str</span>) |
840 | 446: <span class="ruby-identifier">str</span>. |
841 | 447: <span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/&#8211;/</span>, <span class="ruby-value str">'-'</span>). <span class="ruby-comment cmt"># en-dash</span> |
842 | 448: <span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/&#8212;/</span>, <span class="ruby-value str">'--'</span>). <span class="ruby-comment cmt"># em-dash</span> |
843 | 449: |
844 | 450: <span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/&#8216;/</span>, <span class="ruby-value str">"'"</span>). <span class="ruby-comment cmt"># open single quote</span> |
845 | 451: <span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/&#8217;/</span>, <span class="ruby-value str">"'"</span>). <span class="ruby-comment cmt"># close single quote</span> |
846 | 452: |
847 | 453: <span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/&#8220;/</span>, <span class="ruby-value str">'"'</span>). <span class="ruby-comment cmt"># open double quote</span> |
848 | 454: <span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/&#8221;/</span>, <span class="ruby-value str">'"'</span>). <span class="ruby-comment cmt"># close double quote</span> |
849 | 455: |
850 | 456: <span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/&#8230;/</span>, <span class="ruby-value str">'...'</span>) <span class="ruby-comment cmt"># ellipsis</span> |
851 | 457: <span class="ruby-keyword kw">end</span> |
852 | </pre> |
853 | </div> |
854 | </div> |
855 | </div> |
856 | |
857 | <div id="method-M000012" class="method-detail"> |
858 | <a name="M000012"></a> |
859 | |
860 | <div class="method-heading"> |
861 | <a href="#M000012" class="method-signature"> |
862 | <span class="method-name">tokenize</span><span class="method-args">()</span> |
863 | </a> |
864 | </div> |
865 | |
866 | <div class="method-description"> |
867 | <p> |
868 | Return an array of the tokens comprising the string. Each token is either a |
869 | tag (possibly with nested, tags contained therein, such as <tt><a |
870 | href="<MTFoo>"></tt>, or a run of text between tags. |
871 | Each element of the array is a two-element array; the first is either :tag |
872 | or :text; the second is the actual value. |
873 | </p> |
874 | <p> |
875 | Based on the <tt>_tokenize()</tt> subroutine from Brad Choate’s |
876 | MTRegex plugin. <<a |
877 | href="http://www.bradchoate.com/past/mtregex.php">www.bradchoate.com/past/mtregex.php</a>> |
878 | </p> |
879 | <p> |
880 | This is actually the easier variant using tag_soup, as used by Chad Miller |
881 | in the Python port of SmartyPants. |
882 | </p> |
883 | <p><a class="source-toggle" href="#" |
884 | onclick="toggleCode('M000012-source');return false;">[Source]</a></p> |
885 | <div class="method-source-code" id="M000012-source"> |
886 | <pre> |
887 | <span class="ruby-comment cmt"># File rubypants.rb, line 471</span> |
888 | 471: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">tokenize</span> |
889 | 472: <span class="ruby-identifier">tag_soup</span> = <span class="ruby-regexp re">/([^<]*)(<[^>]*>)/</span> |
890 | 473: |
891 | 474: <span class="ruby-identifier">tokens</span> = [] |
892 | 475: |
893 | 476: <span class="ruby-identifier">prev_end</span> = <span class="ruby-value">0</span> |
894 | 477: <span class="ruby-identifier">scan</span>(<span class="ruby-identifier">tag_soup</span>) { |
895 | 478: <span class="ruby-identifier">tokens</span> <span class="ruby-operator"><<</span> [<span class="ruby-identifier">:text</span>, <span class="ruby-identifier">$1</span>] <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">$1</span> <span class="ruby-operator">!=</span> <span class="ruby-value str">""</span> |
896 | 479: <span class="ruby-identifier">tokens</span> <span class="ruby-operator"><<</span> [<span class="ruby-identifier">:tag</span>, <span class="ruby-identifier">$2</span>] |
897 | 480: |
898 | 481: <span class="ruby-identifier">prev_end</span> = <span class="ruby-identifier">$~</span>.<span class="ruby-identifier">end</span>(<span class="ruby-value">0</span>) |
899 | 482: } |
900 | 483: |
901 | 484: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">prev_end</span> <span class="ruby-operator"><</span> <span class="ruby-identifier">size</span> |
902 | 485: <span class="ruby-identifier">tokens</span> <span class="ruby-operator"><<</span> [<span class="ruby-identifier">:text</span>, <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">prev_end</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>]] |
903 | 486: <span class="ruby-keyword kw">end</span> |
904 | 487: |
905 | 488: <span class="ruby-identifier">tokens</span> |
906 | 489: <span class="ruby-keyword kw">end</span> |
907 | </pre> |
908 | </div> |
909 | </div> |
910 | </div> |
911 | |
912 | |
913 | </div> |
914 | |
915 | |
916 | </div> |
917 | |
918 | |
919 | <div id="validator-badges"> |
920 | <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p> |
921 | </div> |
922 | |
923 | </body> |
924 | </html> |