[ANN] PHP SmartyPants Typographer 1.0b2
michel.fortin at michelf.com
Wed Jun 28 18:15:09 EDT 2006
As I stated before, I had in the work a utility to control spaces
around punctuation and at some other places. Now, I've integrated it,
with a few extra quote goodies, within PHP SmartyPants, as an
extension just like PHP Markdown Extra extends PHP Markdown.
And so appeared SmartyPants Typographer (announcement on my weblog)
PHP SmartyPants Typographer 1.0 (documentation page)
PHP SmartyPants (download page)
Note: This version of Typographer is based on SmartyPants 1.5.1oo. It
does not support arrows or the multiply sign which were added in the
latest beta of SmartyPants 1.6. They'll be added eventually.
SmartyPants Typographer let you substitue "straight" double quotes
into any kind of quote. You can define what type of quote to use with
these configuration variables near the top of the file:
# Openning and closing smart double-quotes.
define( 'SMARTYPANTS_SMART_DOUBLEQUOTE_OPEN', "“" );
define( 'SMARTYPANTS_SMART_DOUBLEQUOTE_CLOSE', "”" );
which by default are the “standard” double-quotes for english. Single
quotes are not configurable like this since it would cause problems
with apostrophes. ``Backtick quotes'' are also unaffected by this
SmartyPants Typographer adds ,,double-comma,, quotes, so you can
create ,,German-style`` or ''Greck-style,, quotes. It will also
convert << angle quotes >> in >>any direction<< to guillemets, but
only when they aren't <<ambiguous>> with tags (<< will work too).
You can pass 'c' in the SmartyPants parser attributes to enable comma
quotes and 'g' to enable guillemets. All options are enabled by default.
SmartyPants Typographer can arrange spacing around punctuation signs
by inserting, removing, or simply making unbreakable spaces where
appropriate. Since typography rules aren't exactly constant across
languages, or even within one language (French in particular),
SmartyPants Typographer will not remove or insert spaces by default:
it will just make them unbreakable where it is almost certain they
should be and leave the rest to custom configuration.
SmartyPants Typographer controls spaces around these punctuation
signs (controlled spaces are replaced by `_` for clarity):
* around em-dashes: "He_—_or she_—_should change that."
* around en-dashes: "He_–_or she_–_should change that."
* before a colon: "He said_: here it is."
* before a semicolon: "That's what I said_; that's what he said."
* before a question mark and an exclamation mark: "Hop_! What_?"
* inside french quotes: "Voici la «_chose_» qui m'a attaqué."
* as thousand separator: "On compte 10_000 maisons sur cette liste."
* before a unit abreviation: "This 12_kg of matter costs 10_$."
You can control which transformations applies and what each should do
(replace, insert, remove) by adding the proper characters to parser
attributes. Each of these spaces is represented by a character which
can optionally be followed by a plus sign (+) or a minus sign (-) to
either force insert or remove the space, otherwise only existing
spaces will be replaced. The characters are:
: -> colon spacing +-
; -> semicolon spacing +-
m -> question and exclamation marks spacing +-
h -> em-dash spacing +-
H -> en-dash spacing +-
f -> french quote spacing +-
t -> thousand separator spacing -
u -> unit spacing +-
(Note: thousand separators cannot be added automatically.)
Each of these spaces are, by default, replaced by an unbrekable space
if already present, except for spaces around em- and en- dashes which
are replaced by normal spaces. You can choose independently which
kind of space (unbreakable or not) should be used for each of these
cases with the proper configuration variables near the top of the
file. Well, it doesn't even need to be a space: you could use "_" and
you would get the results I've shown above.
michel.fortin at michelf.com
More information about the Markdown-Discuss