Cutief8

Translate plain ASCII punctuation into “smart” UTF-8


cutief8.pl is a Perl script that takes a plain ASCII file as input and outputs the text with ASCII quotes, double-dashes, and triple-periods replaced by “smart” UTF-8 left and right quotes, em- or en-dashes, and ellipsis

I take almost no credit for this program. It was mostly programatically generated from John Gruber’s original “SmartyPants”, which produces HTML numeric entities rather than UTF-8. (The name has nothing to do with "Qt". It is a bit of a play on the name of the program it was derived from.)

Download:

cutief8.pl (22 kB Perl script)

Man Page:

(from the pod text in the file)


NAME

Cutief8


SYNOPSIS

cutief8.pl [ -t ] [ -n ] [ -m ] [ -1 ] [ -2 ] [ -3 ] [ -r ] [ --version ] [ --shortversion ] [ file ]


DESCRIPTION

Cutief8 is a utility that translates plain ASCII punctuation characters into "smart" UTF-8 typographic punctuation characters. cutief8 can perform the following transformations:

  • Straight quotes ( " and ' ) into "curly" quote UTF-8 characters

  • Backticks-style quotes (``like this'') into "curly" quote UTF-8 characters

  • Dashes (-- and ---) into en- and em-dash characters

  • Three consecutive dots (...) into an ellipsis character

If the 't' option is set the text is assumed to be HTML, and Cutief8 will not modify characters within HTML tags, or inside<pre>, <code>, <kbd>, <script>, or <math> tag blocks. Typically, these blocks are used to display text where smart quotes and other "smart punctuation" would not be appropriate, such as source code or example markup. Without the 't' option, all text is processed, and angle-brackets are assumed to be normal text.

Backslash Escapes

If you need to use literal straight quotes (or plain hyphens and periods), Cutief8 accepts the following backslash escape sequences to force non-smart punctuation. It does so by transforming the escaped character temporarily into an HTML numeric entity, then back again after processing (with the backslash removed):

              Escape
              ------
                \\
                \"
                \'
                \.
                \-
                \`

This is useful, for example, when you want to use straight quotes as foot and inch marks: 6'2" tall; a 17" iMac.


OPTIONS

Use "--" to end switch parsing. For example, to open a file named "-z", use:

        cutief8.pl -- -z
-t

Indicates that the text contains HTML tags, which won't be converted. The text should not contain stray '<' and '>' characters, as these may confuse things. If the option is not set, all the text is converted.

-1

Performs default Cutief8 transformations: quotes (including backticks-style), em-dashes, and ellipses. '--' (dash dash) is used to signify an em-dash; there is no support for en-dashes. This is the default when no options supplied.

-n (or -2)

Same as default -1, except that it uses the old-school typewriter shorthand for dashes: '--' (dash dash) for en-dashes, '---' (dash dash dash) for em-dashes.

-m (or -3)

Same as -n, but inverts the shorthand for dashes: '--' (dash dash) for em-dashes, and '---' (dash dash dash) for en-dashes.

-r

Revert conversions -- turn UTF-8 back to plain ASCII. (Note: en-dashes become plain dashes, em-dashes double-dashes.)

-v, --version

Display the app's name and version number.

-s, --shortversion

Display the short-form version number.

Algorithmic Shortcomings

One situation in which quotes will get curled the wrong way is when apostrophes are used at the start of leading contractions. For example:

    'Twas the night before Christmas.

In the case above, Cutief8 will turn the apostrophe into an opening single-quote, when in fact it should be a closing one. I don't think this problem can be solved in the general case -- every word processor I've tried gets this wrong as well. In such cases, it's best to use the proper UTF-8 character for closing single-quotes (’) by hand.


VERSION HISTORY

    Cutief8 verion 1.0 12 July 2016
    +   Translated the original SmartyPants HTML entities into UTF-8
    using the "Recode" app, with some pre and post processing with  "matt".
    Removed the unused plugin code, and tweaked a few other features
    to be more suitable for standalone use.
    For SmartyPants History, please refer to the original SmartyPants.pl:
    
    http://daringfireball.net/projects/smartypants/
    (Version used for Cutief8: 1.5.1 -- Fri 12 Mar 2004)


AUTHOR

    John Gruber (for SmartyPants)
    http://daringfireball.net
    Pete Goodeve (Cutief8)


COPYRIGHT AND LICENSE

    Cutief8 Copyright (c) 2016 Pete Goodeve
    Licence as for SmartyPants below.
    SmartyPants Copyright (c) 2003 John Gruber
    (http://daringfireball.net/)
    All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

* Neither the name "SmartyPants" nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

This software is provided by the copyright holders and contributors "as is" and any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall the copyright owner or contributors be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage.



               Pete Goodeve
               Berkeley, California

         e-mail: pete@GoodeveCa.NET
         pete.goodeve@computer.org