| 1 |
========================= |
| 2 |
Smart Quotes for Docutils |
| 3 |
========================= |
| 4 |
|
| 5 |
:Author: Günter Milde, |
| 6 |
based on SmartyPants by John Gruber, Brad Choate, and Chad Miller |
| 7 |
:Contact: [email protected] |
| 8 |
:Revision: $Revision$ |
| 9 |
:Date: $Date$ |
| 10 |
:License: Released under the terms of the `2-Clause BSD license`_ |
| 11 |
:Abstract: This document describes the Docutils `smartquotes` module. |
| 12 |
|
| 13 |
.. _2-Clause BSD license: http://opensource.org/licenses/BSD-2-Clause |
| 14 |
|
| 15 |
.. contents:: |
| 16 |
|
| 17 |
Description |
| 18 |
=========== |
| 19 |
|
| 20 |
The `"smart_quotes" configuration setting`_ triggers the SmartQuotes |
| 21 |
transformation on Text nodes that includes the following steps: |
| 22 |
|
| 23 |
- Straight quotes (``"`` and ``'``) into "curly" quote characters |
| 24 |
- dashes (``--`` and ``---``) into en- and em-dash entities |
| 25 |
- three consecutive dots (``...`` or ``. . .``) into an ellipsis entity. |
| 26 |
|
| 27 |
This means you can write, edit, and save your documents using plain old |
| 28 |
ASCII -- straight quotes, plain dashes, and plain dots -- while Docutils |
| 29 |
generates documents with typographical quotes, dashes, and ellipses. |
| 30 |
|
| 31 |
Advantages: |
| 32 |
|
| 33 |
* Typing speed (especially when blind-typing). |
| 34 |
* The possibility to change the quoting style of the |
| 35 |
complete document with just one configuration option. |
| 36 |
* Typographical quotes with just 7-bit ASCII characters in the source. |
| 37 |
|
| 38 |
However, there are `algorithmic shortcomings`_ for 2 reasons: |
| 39 |
|
| 40 |
* Dual use of the "ASCII-apostrophe" (') as single quote and apostrophe. |
| 41 |
* Languages that do not use whitespace around words. |
| 42 |
|
| 43 |
So, please consider also |
| 44 |
`Why You Might Not Want to Use "Smart" Quotes in Your Documents`_. |
| 45 |
|
| 46 |
.. _"smart_quotes" configuration setting: |
| 47 |
.. _"smart_quotes" setting: config.html#smart-quotes |
| 48 |
|
| 49 |
|
| 50 |
Escaping |
| 51 |
======== |
| 52 |
|
| 53 |
The `SmartQuotes` transform does not modify characters in literal text |
| 54 |
such as source code, maths, or literal blocks. |
| 55 |
|
| 56 |
If you need literal straight quotes (or plain hyphens and periods) in normal |
| 57 |
text, you can `backslash escape`_ the characters to preserve |
| 58 |
ASCII-punctuation. |
| 59 |
|
| 60 |
.. class:: booktabs |
| 61 |
|
| 62 |
========= ========= == ======== ========== |
| 63 |
Input Output Input Output |
| 64 |
========= ========= == ======== ========== |
| 65 |
``\\`` \\ ``\...`` \... |
| 66 |
``\"`` \" ``\--`` \-- |
| 67 |
``\'`` \' ``\``` \` |
| 68 |
========= ========= == ======== ========== |
| 69 |
|
| 70 |
This is useful, for example, when you want to use straight quotes as |
| 71 |
foot and inch marks: |
| 72 |
|
| 73 |
6\'2\" tall; a 17\" monitor. |
| 74 |
|
| 75 |
.. _backslash escape: ../ref/rst/restructuredtext.html#escaping-mechanism |
| 76 |
|
| 77 |
|
| 78 |
Localization |
| 79 |
============ |
| 80 |
|
| 81 |
Quotation marks have a `variety of forms`__ in different languages and |
| 82 |
media. |
| 83 |
|
| 84 |
__ https://en.wikipedia.org/wiki/Quotation_mark#Summary_table |
| 85 |
|
| 86 |
`SmartQuotes` inserts quotation marks depending on the language of the |
| 87 |
current block element and the value of the `"smart_quotes" setting`_.\ |
| 88 |
[#x-altquot]_ |
| 89 |
There is built-in support for the following languages:\ [#smartquotes-locales]_ |
| 90 |
|
| 91 |
.. class:: run-in |
| 92 |
|
| 93 |
:af: .. class:: language-af |
| 94 |
|
| 95 |
"'Afrikaans' quotes" |
| 96 |
|
| 97 |
:af-x-altquot: .. class:: language-af-x-altquot |
| 98 |
|
| 99 |
"'Afrikaans' alternative quotes" |
| 100 |
|
| 101 |
:ca: .. class:: language-ca |
| 102 |
|
| 103 |
"'Catalan' quotes" |
| 104 |
|
| 105 |
:ca-x-altquot: .. class:: language-ca-x-altquot |
| 106 |
|
| 107 |
"'Catalan' alternative quotes" |
| 108 |
|
| 109 |
:cs: .. class:: language-cs |
| 110 |
|
| 111 |
"'Czech' quotes" |
| 112 |
|
| 113 |
:cs-x-altquot: .. class:: language-cs-x-altquot |
| 114 |
|
| 115 |
"'Czech' alternative quotes" |
| 116 |
|
| 117 |
:da: .. class:: language-da |
| 118 |
|
| 119 |
"'Danish' quotes" |
| 120 |
|
| 121 |
:da-x-altquot: .. class:: language-da-x-altquot |
| 122 |
|
| 123 |
"'Danish' alternative quotes" |
| 124 |
|
| 125 |
:de: .. class:: language-de |
| 126 |
|
| 127 |
"'German' quotes" |
| 128 |
|
| 129 |
:de-x-altquot: .. class:: language-de-x-altquot |
| 130 |
|
| 131 |
"'German' alternative quotes" |
| 132 |
|
| 133 |
:de-ch: .. class:: language-de-ch |
| 134 |
|
| 135 |
"'Swiss-German' quotes" |
| 136 |
|
| 137 |
:el: .. class:: language-el |
| 138 |
|
| 139 |
"'Greek' quotes" |
| 140 |
|
| 141 |
:en: .. class:: language-en |
| 142 |
|
| 143 |
"'English' quotes" |
| 144 |
|
| 145 |
:en-uk-x-altquot: .. class:: language-en-uk-x-altquot |
| 146 |
|
| 147 |
"'British' alternative quotes" (swaps single and double quotes) |
| 148 |
|
| 149 |
:eo: .. class:: language-eo |
| 150 |
|
| 151 |
"'Esperanto' quotes" |
| 152 |
|
| 153 |
:es: .. class:: language-es |
| 154 |
|
| 155 |
"'Spanish' quotes" |
| 156 |
|
| 157 |
:es-x-altquot: .. class:: language-es-x-altquot |
| 158 |
|
| 159 |
"'Spanish' alternative quotes" |
| 160 |
|
| 161 |
:et: .. class:: language-et |
| 162 |
|
| 163 |
"'Estonian' quotes" (no secondary quote listed in Wikipedia) |
| 164 |
|
| 165 |
:et-x-altquot: .. class:: language-et-x-altquot |
| 166 |
|
| 167 |
"'Estonian' alternative quotes" |
| 168 |
|
| 169 |
:eu: .. class:: language-eu |
| 170 |
|
| 171 |
"'Basque' quotes" |
| 172 |
|
| 173 |
:fi: .. class:: language-fi |
| 174 |
|
| 175 |
"'Finnish' quotes" |
| 176 |
|
| 177 |
:fi-x-altquot: .. class:: language-fi-x-altquot |
| 178 |
|
| 179 |
"'Finnish' alternative quotes" |
| 180 |
|
| 181 |
:fr: .. class:: language-fr |
| 182 |
|
| 183 |
"'French' quotes" |
| 184 |
|
| 185 |
:fr-x-altquot: .. class:: language-fr-x-altquot |
| 186 |
|
| 187 |
"'French' alternative quotes" |
| 188 |
|
| 189 |
:fr-ch: .. class:: language-fr-ch |
| 190 |
|
| 191 |
"'Swiss-French' quotes" |
| 192 |
|
| 193 |
:fr-ch-x-altquot: .. class:: language-fr-ch-x-altquot |
| 194 |
|
| 195 |
"'Swiss-French' alternative quotes" (narrow no-break space, see |
| 196 |
http://typoguide.ch/) |
| 197 |
|
| 198 |
:gl: .. class:: language-gl |
| 199 |
|
| 200 |
"'Galician' quotes" |
| 201 |
|
| 202 |
:he: .. class:: language-he |
| 203 |
|
| 204 |
"'Hebrew' quotes" |
| 205 |
|
| 206 |
:he-x-altquot: .. class:: language-he-x-altquot |
| 207 |
|
| 208 |
"'Hebrew' alternative quotes" |
| 209 |
|
| 210 |
:hr: .. class:: language-hr |
| 211 |
|
| 212 |
"'Croatian' quotes" |
| 213 |
|
| 214 |
:hr-x-altquot: .. class:: language-hr-x-altquot |
| 215 |
|
| 216 |
"'Croatian' alternative quotes" |
| 217 |
|
| 218 |
:hsb: .. class:: language-hsb |
| 219 |
|
| 220 |
"'Upper Sorbian' quotes" |
| 221 |
|
| 222 |
:hsb-x-altquot: .. class:: language-hsb-x-altquot |
| 223 |
|
| 224 |
"'Upper Sorbian' alternative quotes" |
| 225 |
|
| 226 |
:hu: .. class:: language-hu |
| 227 |
|
| 228 |
"'Hungarian' quotes" |
| 229 |
|
| 230 |
:is: .. class:: language-is |
| 231 |
|
| 232 |
"'Icelandic' quotes" |
| 233 |
|
| 234 |
:it: .. class:: language-it |
| 235 |
|
| 236 |
"'Italian' quotes" |
| 237 |
|
| 238 |
:it-ch: .. class:: language-it-ch |
| 239 |
|
| 240 |
"'Swiss-Italian' quotes" |
| 241 |
|
| 242 |
:it-x-altquot: .. class:: language-it-x-altquot |
| 243 |
|
| 244 |
"'Italian' alternative quotes" |
| 245 |
|
| 246 |
:ja: .. class:: language-ja |
| 247 |
|
| 248 |
"'Japanese' quotes" |
| 249 |
|
| 250 |
:lt: .. class:: language-lt |
| 251 |
|
| 252 |
"'Lithuanian' quotes" |
| 253 |
|
| 254 |
:lv: .. class:: language-lv |
| 255 |
|
| 256 |
"'Latvian' quotes" |
| 257 |
|
| 258 |
:nl: .. class:: language-nl |
| 259 |
|
| 260 |
"'Dutch' quotes" |
| 261 |
|
| 262 |
:nl-x-altquot: .. class:: language-nl-x-altquot |
| 263 |
|
| 264 |
"'Dutch' alternative quotes" |
| 265 |
|
| 266 |
.. # 'nl-x-altquot2': '””’’', |
| 267 |
|
| 268 |
:pl: .. class:: language-pl |
| 269 |
|
| 270 |
"'Polish' quotes" |
| 271 |
|
| 272 |
:pl-x-altquot: .. class:: language-pl-x-altquot |
| 273 |
|
| 274 |
"'Polish' alternative quotes" |
| 275 |
|
| 276 |
:pt: .. class:: language-pt |
| 277 |
|
| 278 |
"'Portuguese' quotes" |
| 279 |
|
| 280 |
:pt-br: .. class:: language-pt-br |
| 281 |
|
| 282 |
"'Portuguese (Brazil)' quotes" |
| 283 |
|
| 284 |
:ro: .. class:: language-ro |
| 285 |
|
| 286 |
"'Romanian' quotes" |
| 287 |
|
| 288 |
:ru: .. class:: language-ru |
| 289 |
|
| 290 |
"'Russian' quotes" |
| 291 |
|
| 292 |
:sh: .. class:: language-sh |
| 293 |
|
| 294 |
"'Serbo-Croatian' quotes" |
| 295 |
|
| 296 |
:sh-x-altquot: .. class:: language-sh-x-altquot |
| 297 |
|
| 298 |
"'Serbo-Croatian' alternative quotes" |
| 299 |
|
| 300 |
:sk: .. class:: language-sk |
| 301 |
|
| 302 |
"'Slovak' quotes" |
| 303 |
|
| 304 |
:sk-x-altquot: .. class:: language-sk-x-altquot |
| 305 |
|
| 306 |
"'Slovak' alternative quotes" |
| 307 |
|
| 308 |
:sl: .. class:: language-sl |
| 309 |
|
| 310 |
"'Slovenian' quotes" |
| 311 |
|
| 312 |
:sl-x-altquot: .. class:: language-sl-x-altquot |
| 313 |
|
| 314 |
"'Slovenian' alternative quotes" |
| 315 |
|
| 316 |
:sr: .. class:: language-sr |
| 317 |
|
| 318 |
"'Serbian' quotes" |
| 319 |
|
| 320 |
:sr-x-altquot: .. class:: language-sr-x-altquot |
| 321 |
|
| 322 |
"'Serbian' alternative quotes" |
| 323 |
|
| 324 |
:sv: .. class:: language-sv |
| 325 |
|
| 326 |
"'Swedish' quotes" |
| 327 |
|
| 328 |
:sv-x-altquot: .. class:: language-sv-x-altquot |
| 329 |
|
| 330 |
"'Swedish' alternative quotes" |
| 331 |
|
| 332 |
:tr: .. class:: language-tr |
| 333 |
|
| 334 |
"'Turkish' quotes" |
| 335 |
|
| 336 |
:tr-x-altquot: .. class:: language-tr-x-altquot |
| 337 |
|
| 338 |
"'Turkish' alternative quotes" |
| 339 |
|
| 340 |
.. 'tr-x-altquot2': '“„‘‚', # antiquated? |
| 341 |
|
| 342 |
:uk: .. class:: language-uk |
| 343 |
|
| 344 |
"'Ukrainian' quotes" |
| 345 |
|
| 346 |
:uk-x-altquot: .. class:: language-uk-x-altquot |
| 347 |
|
| 348 |
"'Ukrainian' alternative quotes" |
| 349 |
|
| 350 |
:zh-cn: .. class:: language-zh-cn |
| 351 |
|
| 352 |
"'Chinese (China)' quotes" |
| 353 |
|
| 354 |
:zh-tw: .. class:: language-zh-tw |
| 355 |
|
| 356 |
"'Chinese (Taiwan)' quotes" |
| 357 |
|
| 358 |
Quotes in text blocks in a non-configured language are kept as plain quotes: |
| 359 |
|
| 360 |
:undefined: .. class:: language-undefined-example |
| 361 |
|
| 362 |
"'Undefined' quotes" |
| 363 |
|
| 364 |
.. [#x-altquot] Tags with the non-standard extension ``-x-altquot`` define |
| 365 |
the quote set used with the `"smart_quotes" setting`_ value ``"alt"``. |
| 366 |
|
| 367 |
.. [#smartquotes-locales] The definitions for language-dependend |
| 368 |
typographical quotes can be extended or overwritten using the |
| 369 |
`"smartquotes_locales" setting`_. |
| 370 |
|
| 371 |
The following example ensures a correct leading apostrophe in ``'s |
| 372 |
Gravenhage`` (at the cost of incorrect leading single quotes) in Dutch |
| 373 |
and sets French quotes to double and single guillemets with inner |
| 374 |
spacing:: |
| 375 |
|
| 376 |
smartquote-locales: nl: „”’’ |
| 377 |
fr: « : »:‹ : › |
| 378 |
|
| 379 |
.. _"smartquotes_locales" setting: config.html#smartquotes-locales |
| 380 |
|
| 381 |
|
| 382 |
Caveats |
| 383 |
======= |
| 384 |
|
| 385 |
Why You Might Not Want to Use "Smart" Quotes in Your Documents |
| 386 |
-------------------------------------------------------------- |
| 387 |
|
| 388 |
For one thing, you might not care. |
| 389 |
|
| 390 |
Most normal, mentally stable individuals do not take notice of proper |
| 391 |
typographic punctuation. Many design and typography nerds, however, break |
| 392 |
out in a nasty rash when they encounter, say, a restaurant sign that uses |
| 393 |
a straight apostrophe to spell "Joe's". |
| 394 |
|
| 395 |
If you're the sort of person who just doesn't care, you might well want to |
| 396 |
continue not caring. Using straight quotes -- and sticking to the 7-bit |
| 397 |
ASCII character set in general -- is certainly a simpler way to live. |
| 398 |
|
| 399 |
Even if you *do* care about accurate typography, you still might want to |
| 400 |
think twice before "auto-educating" the quote characters in your documents. |
| 401 |
As there is always a chance that the algorithm gets it wrong, you may |
| 402 |
instead prefer to use the compose key or some other means to insert the |
| 403 |
correct Unicode characters into the source. |
| 404 |
|
| 405 |
|
| 406 |
Algorithmic Shortcomings |
| 407 |
------------------------ |
| 408 |
|
| 409 |
The ASCII character (u0027 APOSTROPHE) is used for apostrophe and single |
| 410 |
quotes. If used inside a word, it is converted into an apostrophe: |
| 411 |
|
| 412 |
.. class:: language-fr |
| 413 |
|
| 414 |
Il dit : "C'est 'super' !" |
| 415 |
|
| 416 |
At the beginning or end of a word, it cannot be distinguished from a single |
| 417 |
quote by the algorithm. |
| 418 |
|
| 419 |
The `right single quotation mark`_ character -- used to close a secondary |
| 420 |
(inner) quote in English -- is also "the preferred character to use for |
| 421 |
apostrophe" (Unicode_). Therefore, "educating" works as expected for |
| 422 |
apostrophes at the end of a word, e.g., |
| 423 |
|
| 424 |
Mr. Hastings' pen; three days' leave; my two cents' worth. |
| 425 |
|
| 426 |
However, when apostrophes are used at the start of leading contractions, |
| 427 |
"educating" will turn the apostrophe into an *opening* secondary quote. In |
| 428 |
English, this is *not* the apostrophe character, e.g., ``'Twas brillig`` |
| 429 |
is "miseducated" to |
| 430 |
|
| 431 |
'Twas brillig. |
| 432 |
|
| 433 |
In other locales (French, Italian, German, ...), secondary closing quotes |
| 434 |
differ from the apostrophe. A text like:: |
| 435 |
|
| 436 |
.. class:: language-de-CH |
| 437 |
|
| 438 |
"Er sagt: 'Ich fass' es nicht.'" |
| 439 |
|
| 440 |
becomes |
| 441 |
|
| 442 |
«Er sagt: ‹Ich fass› es nicht.›» |
| 443 |
|
| 444 |
with a single closing guillemet in place of the apostrophe. |
| 445 |
|
| 446 |
In such cases, it's best to use the recommended apostrophe character (’) in |
| 447 |
the source: |
| 448 |
|
| 449 |
| ’Twas brillig, and the slithy toves |
| 450 |
| Did gyre and gimble in the wabe; |
| 451 |
| All mimsy were the borogoves, |
| 452 |
| And the mome raths outgrabe. |
| 453 |
|
| 454 |
.. _right single quotation mark: |
| 455 |
http://www.fileformat.info/info/unicode/char/2019/index.htm |
| 456 |
.. _Unicode: https://www.unicode.org/charts/PDF/U2000.pdf |
| 457 |
|
| 458 |
History |
| 459 |
======= |
| 460 |
|
| 461 |
The smartquotes module is an adaption of "SmartyPants_" to Docutils. |
| 462 |
|
| 463 |
`John Gruber`_ did all of the hard work of writing this software in Perl for |
| 464 |
`Movable Type`_ and almost all of this useful documentation. `Chad Miller`_ |
| 465 |
ported it to Python to use with Pyblosxom_. |
| 466 |
|
| 467 |
Portions of the SmartyPants original work are based on Brad Choate's nifty |
| 468 |
MTRegex plug-in. `Brad Choate`_ also contributed a few bits of source code to |
| 469 |
this plug-in. Brad Choate is a fine hacker indeed. |
| 470 |
`Jeremy Hedley`_ and `Charles Wiltgen`_ deserve mention for exemplary beta |
| 471 |
testing of the original SmartyPants. |
| 472 |
|
| 473 |
Internationalization and adaption to Docutils by Günter Milde. |
| 474 |
|
| 475 |
.. _SmartyPants: http://daringfireball.net/projects/smartypants/ |
| 476 |
.. _Pyblosxom: http://pyblosxom.bluesock.org/ |
| 477 |
.. _Movable Type: http://www.movabletype.org/ |
| 478 |
.. _John Gruber: http://daringfireball.net/ |
| 479 |
.. _Chad Miller: http://web.chad.org/ |
| 480 |
.. _Brad Choate: http://bradchoate.com/ |
| 481 |
.. _Jeremy Hedley: http://antipixel.com/ |
| 482 |
.. _Charles Wiltgen: http://playbacktime.com/ |
| 483 |
.. _Rael Dornfest: http://raelity.org/ |