BBEdit HTML Entity Maker
I am constantly pasting text into BBEdit in the middle of markup. This copy often needs the entities to be encoded before the page can be published or it won't validate. I created this simple perl filter to automatically substitute the correct entitly code for each un-encoded character in a selection of text.
Place the following script in a text file and save it to:
~/Library/Application Support/BBEdit/Unix Support/Unix Filters/
You'll now have a new item in the #! menu of BBEdit under Unix Filters. Just select a bunch of text containing un-encoded entities and choose this menu item to convert it.
#!/usr/bin/perl -w
#
# used as a filter in bbedit to form html entities
#
# Refactored by Joshua McFarren 1/08/10
# This work is licensed under a Creative Commons License.
# http://creativecommons.org/licenses/by-sa/2.0/
use strict;
my %queries =
(
' ?\(R\)',
'®',
'\(C\)',
'©',
' & ',
' & ',
'\bFH&R\b',
'FH&R',
' ?\(TM\)',
'™',
' - ',
' – ',
'(\b\d{1,2})-(\$?\d{1,2}\b)',
'$1–$2',
'([^!])--([^>])',
'$1—$2',
'À',
'À',
'Á',
'Á',
'Â',
'Â',
'Ã',
'Ã',
'Ä',
'Ä',
'Å',
'Å',
'à',
'à',
'á',
'á',
'â',
'â',
'ã',
'ã',
'ä',
'ä',
'å',
'å',
'Ç',
'Ç',
'ç',
'ç',
'È',
'È',
'É',
'É',
'Ê',
'Ê',
'Ë',
'Ë',
'è',
'è',
'é',
'é',
'ê',
'ê',
'ë',
'ë',
'Ì',
'Ì',
'Í',
'Í',
'Î',
'Î',
'Ï',
'Ï',
'ì',
'ì',
'í',
'í',
'î',
'î',
'ï',
'ï',
'Ñ',
'Ñ',
'ñ',
'ñ',
'Ò',
'Ò',
'Ó',
'Ó',
'Ô',
'Ô',
'Õ',
'Õ',
'Ö',
'Ö',
'Ø',
'Ø',
'ò',
'ò',
'ó',
'ó',
'ô',
'ô',
'õ',
'õ',
'ö',
'ö',
'ø',
'ø',
'Ù',
'Ù',
'Ú',
'Ú',
'Û',
'Û',
'Ü',
'Ü',
'ù',
'ù',
'ú',
'ú',
'û',
'û',
'ü',
'ü',
'ÿ',
'ÿ',
'Ÿ',
'Ÿ',
'¡',
'¡',
'¢',
'¢',
'£',
'£',
'¥',
'¥',
'§',
'§',
'¨',
'¨',
'©',
'©',
'ª',
'ª',
'«',
'«',
'¬',
'¬',
'®',
'®',
'¯',
'¯',
'°',
'°',
'±',
'±',
'´',
'´',
'µ',
'µ',
'¶',
'¶',
'·',
'·',
'¸',
'¸',
'º',
'º',
'»',
'»',
'–',
'–',
'—',
'—',
'‘',
'‘',
'’',
'’',
'‚',
'‚',
'“',
'“',
'”',
'”',
'„',
'„',
'†',
'†',
'‡',
'‡',
'•',
'•',
'…',
'…',
'‰',
'‰',
'‹',
'‹',
'›',
'›',
'¿',
'¿',
'Æ',
'Æ',
'æ',
'æ',
'ß',
'ß',
'÷',
'÷',
'Œ',
'Œ',
'œ',
'œ',
'ƒ',
'ƒ',
'ˆ',
'ˆ',
'˜',
'˜',
'Ω',
'Ω',
'π',
'π',
'(Membership\s+Rewards(\(R\)|®)?( First(\(SM\))?)?)',
'<span class="nobr">$1</span>',
'\b((1-)?(\d{3})-(\d{3}|[A-Z]{3})-(\d{4}|[A-Z]{4})(\.|,|;|:)?)',
'<span class="nobr">$1</span>',
'(\(\d{3}-\d{4}\))',
'<span class="nobr">$1</span>'
);
my $input =
'';
while (<>
) {
$input .=
$_;
}
while (($find,
$replace) =
each(%queries)) {
$input =~
s#$find#$replace#g;
}
print "$input";
CategoryCode