PHP SmartyPants Typographer

Faire un don

Typographer is an extension to SmartyPants adding support for different quotation marks as well as for converting normal spaces to unbreakable spaces and thus preventing inappropriate line breaks. You can download SmartyPants Typographer on the main page for PHP SmartyPants.

Quotation Marks

SmartyPants will change strait quotes with curled quotes in an intelligent way. SmartyPants Typographer adds options to support other quotation marks as used in many languages.

You can now transform "straight" double-quotes in whatever mark you want by changing the appropriate configuration strings at the start of the file:

# Opening and closing smart double-quotes.
define( 'SMARTYPANTS_SMART_DOUBLEQUOTE_OPEN',  "“" );
define( 'SMARTYPANTS_SMART_DOUBLEQUOTE_CLOSE', "”" );

which by default are set to “english-style” quotes. English ‘single quotes’ are not configurable in this way because it would cause problem with apostrophes. ``backtick quotes'' are not affected by this setting.

SmartyPants Typographer also support ,,double-comma,, quotation marks, which can be used to create ,,german-`` or ''greek-,, style curly quotes. It will also convert << double-angle >> quotes written in >>any direction<< to typographic angle quote characters, but only when they are unambiguous with HTML tags.

Configuration

You can add “c” to SmartyPants attributes to activate double-comma quotes and “g” for angle quotes. All these options are enabled by default.

Spaces

The space normalization performed by SmartyPants Typographer should adapt to any language. Defaults are set so that no space is inserted or removed: normal breakable spaces are replaced by unbreakable spaces where it is not appropriate for a line break to occur.

If you write a number followed by a unit symbol (say 12 kg), SmartyPants Typographer will change the space between the number and the unit to make it unbreakable. If someone put a space before a question mark, for instance, the space will be preserved as intended by the author, but it will be made unbreakable since it is inadvisable to break a line just before a question mark. Replacement with unbreakable space characters should pass pretty much unnoticed, except for the fact that there won’t be wrong line line breaks anymore.

SmartyPants Typographer makes spaces unbreakable in the following cases (unbreakable spaces are shown as underbars “_” to make them visible):

Space normalization also makes sure that spaces around em- and en- dashes are breakable (normal) spaces:

You can also configure SmartyPants Typographer to force the insertion or the removal of spaces in all the previously mentioned cases to enforce specific typographic rules.

Particular attention has been ported to some special cases to make sure they work well:

Configuration

You can control what transformations will apply (replace, insert, remove space) for each one of the space categories by adding the right characters to SmartyPants attributes. Each of these categories is represented by one character which can optionally be followed by a plus (+) or a minus (-) sign to respectively force the insertion or the removal of the space. Characters categories are:

Character Space
: colon
; semicolon
m question and exclamation marks
h em-dash
H en-dash
f french quotes
t thousand separator
u value and unit

(Note: thousand separator space cannot be added automatically.)

For example, to force the insertion of a space inside french quotes and before the colon, make unbreakable already-existing spaces before a unit and used as a thousand separator, and to remove any space before a semicolon as well as the question and exclamation marks, use the following configuration string: "f+:+ut;-m-"

You can also choose, for each one of these categories, which replacement character will be used by changing the appropriate configuration variables near the start of the SmartyPants file.