March 16, 2005
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:
BBEdit > BBEdit Support > 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 Unix Filter in the BBEdit #! menu to form html entities # # Written by Joshua McFarren 1/20/05 # This work is licensed under a Creative Commons License. # http://creativecommons.org/licenses/by-sa/2.0/ use strict; my $input = ""; while (<>) { $input .= $_; } $input =~ s/\(R\)/®/g; $input =~ s/\(C\)/©/g; $input =~ s/\(TM\)/™/g; $input =~ s/ & / & /g; $input =~ s/ - / – /g; $input =~ s/([^!])--([^>])/$1—$2/g; # safe em $input =~ s/À/À/g; $input =~ s/Á/Á/g; $input =~ s/Â/Â/g; $input =~ s/Ã/Ã/g; $input =~ s/Ä/Ä/g; $input =~ s/Å/Å/g; $input =~ s/à/à/g; $input =~ s/á/á/g; $input =~ s/â/â/g; $input =~ s/ã/ã/g; $input =~ s/ä/ä/g; $input =~ s/å/å/g; $input =~ s/Ç/Ç/g; $input =~ s/ç/ç/g; $input =~ s/È/È/g; $input =~ s/É/É/g; $input =~ s/Ê/Ê/g; $input =~ s/Ë/Ë/g; $input =~ s/è/è/g; $input =~ s/é/é/g; $input =~ s/ê/ê/g; $input =~ s/ë/ë/g; $input =~ s/Ì/Ì/g; $input =~ s/Í/Í/g; $input =~ s/Î/Î/g; $input =~ s/Ï/Ï/g; $input =~ s/ì/ì/g; $input =~ s/í/í/g; $input =~ s/î/î/g; $input =~ s/ï/ï/g; $input =~ s/Ñ/Ñ/g; $input =~ s/ñ/ñ/g; $input =~ s/Ò/Ò/g; $input =~ s/Ó/Ó/g; $input =~ s/Ô/Ô/g; $input =~ s/Õ/Õ/g; $input =~ s/Ö/Ö/g; $input =~ s/Ø/Ø/g; $input =~ s/ò/ò/g; $input =~ s/ó/ó/g; $input =~ s/ô/ô/g; $input =~ s/õ/õ/g; $input =~ s/ö/ö/g; $input =~ s/ø/ø/g; $input =~ s/Ù/Ù/g; $input =~ s/Ú/Ú/g; $input =~ s/Û/Û/g; $input =~ s/Ü/Ü/g; $input =~ s/ù/ù/g; $input =~ s/ú/ú/g; $input =~ s/û/û/g; $input =~ s/ü/ü/g; $input =~ s/ÿ/ÿ/g; $input =~ s/Ÿ/Ÿ/g; $input =~ s/¡/¡/g; $input =~ s/¢/¢/g; $input =~ s/£/£/g; $input =~ s/¥/¥/g; $input =~ s/§/§/g; $input =~ s/¨/¨/g; $input =~ s/©/©/g; $input =~ s/ª/ª/g; $input =~ s/«/«/g; $input =~ s/¬/¬/g; $input =~ s/®/®/g; $input =~ s/¯/¯/g; $input =~ s/°/°/g; $input =~ s/±/±/g; $input =~ s/´/´/g; $input =~ s/µ/µ/g; $input =~ s/¶/¶/g; $input =~ s/·/·/g; $input =~ s/¸/¸/g; $input =~ s/º/º/g; $input =~ s/»/»/g; $input =~ s/–/–/g; $input =~ s/—/—/g; $input =~ s/‘/‘/g; $input =~ s/’/’/g; $input =~ s/‚/‚/g; $input =~ s/“/“/g; $input =~ s/”/”/g; $input =~ s/„/„/g; $input =~ s/†/†/g; $input =~ s/‡/‡/g; $input =~ s/•/•/g; $input =~ s/…/…/g; $input =~ s/‰/‰/g; $input =~ s/‹/‹/g; $input =~ s/›/›/g; $input =~ s/¿/¿/g; $input =~ s/Æ/Æ/g; $input =~ s/æ/æ/g; $input =~ s/ß/ß/g; $input =~ s/÷/÷/g; $input =~ s/Œ/Œ/g; $input =~ s/œ/œ/g; $input =~ s/ƒ/ƒ/g; $input =~ s/ˆ/ˆ/g; $input =~ s/˜/˜/g; $input =~ s/Ω/Ω/g; $input =~ s/π/π/g; print "$input"; |
This work is licensed under a Creative Commons License.
Technorati tags: bbedit, perl, webdesign, web design, htmlPosted by joshua at March 16, 2005 10:00 PM
Post a comment