Download: amputator.tar.gz (4.6 KB)
Amputator is a free plugin for Movable Type and Blosxom. It safely rewrites ampersand characters as an HTML entity reference: “&”.
If you want your HTML or XHTML to display smoothly across browsers and platforms, you need to use a little finesse with non-ASCII characters such as curly quotes, or “ä” or “™.” If you view source on this page, you’ll see I specified those last two characters by writing “ä” and “™.”
Sequences like “™” are called entity references, and their sole benefit is that they can be expressed in plain ASCII. HTML includes heaps of entity references to stand in for various accented and otherwise special characters not found in ASCII. Entity references all start with ampersands, and end with semicolons.
Unfortunately, HTML and XML reserve the ampersand exclusively for entity references. Any time you use an ampersand by itself, for example within the token delimiters of GET-style URLs like this one, the HTML parser will try to read it like the start of a nonexistent entity reference. Any decent browser will catch the error and recover, but it’s still a mistake, and your HTML won’t validate.
You can make your HTML clean again by replacing the ampersand with an entity reference for an ampersand. So instead of just “&”, you’d write “&”, and the browser will make the last-minute substitution.
Amputator steps in to relieve you of the crushing, trivial burden of replacing all those ampersands yourself. After installation into Movable Type or Blosxom, you can freely gab about Law & Order and Brown & Williamson, while your ampersands will be replaced by entity references on the fly, as you publish.
Of course, Amputator is smart enough to ignore ampersands attached to existing entities. Otherwise, writing “é” would come out “é”, and nobody likes that except the odd technical writer.
Amputator requires Movable Type version 2.5 or later, and works fine with Movable Type 3.x.
(MT home)/plugins/Amputator.pl
If you're using the MT "dynamic publishing" model, you'll want to install the PHP version of the Amputator plugin. Copy the "modifier.encode_ampersands.php" file from the "optional" folder of the Amputator distribution into MT's PHP plugins folder:
(MT home)/php/plugins/modifier.encode_ampersands.php
You can skip this step if you're not using dynamic publishing, but there's no harm installing it.
<$MTEntryBody$>
becomes:
<$MTEntryBody encode_ampersands="1"$>
Easy! Ditto for <$MTEntryMore$>, or <$MTEntryTitle$>:
<$MTEntryMore encode_ampersands="1"$>
<$MTEntryTitle encode_ampersands="1"$>
You're done.
Amputator requires Blosxom version 2.0 or later.
I know of only one case where Amputator improperly replaces an ampersand: if you're using a JavaScript snippet inside of a weblog entry, Amputator may convert an ampersand intended for the JavaScript interpreter instead of the browser, confusing the interpreter. If this problem affects you, please let me know at the address below so we can discuss a solution.
Aside from that, if you encounter a problem, please and tell me all about it.
SmartyPants: http://daringfireball.net/projects/smartypants/
1.2 Friday, August 26, 2005
1.1.1 Mon, Feb 21, 2005
1.1 Tue, March 16, 2004
1.0: Thu, March 6, 2003
Documentation revised September 28, 2003.
Nat Irons
http://bumppo.net
John Gruber precipitated the release of this plugin by providing several good reasons why he was unwilling to make SmartyPants take care if it for me.
Max Barry suggested adding Blosxom support, after a previous ampersand-replacing plugin for Blosxom went AWOL.
Grettir Asmundarson and Chad Everett contributed code.
Copyright (c) 2003 Nathaniel Irons. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl.