Tuesday, March 02, 2004

ASCII art to Blogger post...

Perl one-liner to convert ASCII art to a format that can be pasted directly into Blogger.
perl -MHTML::Entities -p -e "encode_entities($_); s/ / /g; s/\\/\/g"
  • This relies on outside HTML or CSS to set the font to something suitablly monospace.
  • Hard spaces are used instead of relying on <pre>. In order to use <pre> you would have to turn off Blogger's normal newline-to-<br> conversion, and I don't want to turn it off just so I can occasionally post ASCII art.
  • Backslashes are escaped because of the strange way Blogger seems to deal with lines that end with backslashes; it thinks they are continuation characters like in a C macro or something.


Example: (from http://www.chris.com/ascii/art/html/simpsons.html)

                             (####)
                           (#######)
                         (#########)
                        (#########)
                      (#########)
                     (#########)
                    (#########)
                   (#########)
                  (########)
   _____         (#########)
  /     \       (#########)    |\/\/\/|     /\ /\  /\               /\
\/\/     |      (#########)    |      |     | V  \/  \---.    .----/  \----.
 |  (o)(o)       (o)(o)(##)    |      |      \_        /       \          /
 C   .---_)    ,_C     (##)    | (o)(o)       (o)(o)  <__.   .--\ (o)(o) /__.
  | |.___|    /____,   (##)    C      _)     _C         /     \     ()     /
  |  \__/       \     (#)       | ,___|     /____,   )  \      >   (C_)   <
  /_____\        |    |         |   /         \     /----'    /___\____/___\
 /_____/ \       OOOOOO        /____\          ooooo             /|    |\
/         \     /      \      /      \        /     \           /        \

  HOMER          MARGE         BART            LISA               MAGGIE

Comments: