Text::Typography(3pm)

Text::Typography3pm

Markup ascii text with correct typography for html

Usage

    use Text::Typography qw(typography);
    
    print typography($text);

Overview

This module is a thin wrapper for John Gruber's SmartyPants plugin for various CMSs.

SmartyPants is a web publishing utility that translates plain ASCII punctuation characters into "smart" typographic punctuation HTML entities. SmartyPants can perform the following transformations:

•

Straight quotes ( " and ' ) into "curly" quote HTML entities

•

Backticks-style quotes (``like this'') into "curly" quote HTML entities

•

Dashes ("--" and "---") into en- and em-dash entities

•

Three consecutive dots ("...") into an ellipsis entity

SmartyPants does not modify characters within "<pre>", "<code>", "<kbd>", "<script>", or "<math>" tag blocks. Typically, these tags are used to display text where smart quotes and other "smart punctuation" would not be appropriate, such as source code or example markup.

typography($text[, $attributes])

Returns a string marked up with the proper HTML entities for proper typography.

For fine grain control over what gets converted, use the $attributes option. The default value is 3.

The following numeric values set a group of options:

    0 : do nothing
    1 : set all
    2 : set all, using old school en- and em- dash shortcuts (-- and ---)
    3 : set all, using inverted old school en- and em- dash shortcuts (--- and --)

For even finer control, specify a string of one or more of the following characters:

    q : quotes
    b : backtick quotes (``double'' only)
    B : backtick quotes (``double'' and `single')
    d : dashes
    D : old school dashes
    i : inverted old school dashes
    e : ellipses
    w : convert &quot; entities to " for Dreamweaver users

Backslash Escapes

If you need to use literal straight quotes (or plain hyphens and periods), SmartyPants accepts the following backslash escape sequences to force non-smart punctuation. It does so by transforming the escape sequence into a decimal-encoded HTML entity:

              Escape  Value  Character
              ------  -----  ---------
                \\    &#92;    \
                \"    &#34;    "
                \'    &#39;    '
                \.    &#46;    .
                \-    &#45;    -
                \`    &#96;    `

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

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, SmartyPants 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 HTML entity for closing single-quotes ("&#8217;") by hand.

Releases

10 releases since Debian 4.0 (Etch); the text changed 4 times.

  1. 4.0
  2. 5.0–8
  3. 9–10
  4. 11
  5. 12–13

Author

Thomas Sibley created this module using the code from the SmartyPants CMS plugin by John Gruber (<http://daringfireball.net/projects/smartypants/>).

From libtext-typography-perl 0.01-5 in Debian 13 (Trixie). Parsed by carta from the page's man source.