Pasting code in Advogato
Pasting code is something not to be abused here, but I think it would be normal to see it now and then in the diary of software developers more than we do.
That has a couple of inconveniences though, not a big deal, but:
- Special characters have to be substituted with HTML entities.
- mod_virgule doubles blank lines in pre blocks and adds a spurios leading space.
- Escapes special characters.
- Puts a dummy space in blank lines to avoid the bug.
- Indents the whole block.
- Wraps the result in a pre tag.
- Puts the result in the clipboard on Mac OS X and Win32.
Of course the first application of that script has to be to blog his very listing, but since it is a bit long I'll just post a few lines:
#!/usr/bin/perl use strict; use warnings; # indentation of the whole block my $indent = ' ' x 3; # coderef for setting the clipboard my $clip = $^O eq 'darwin' ? \&clip_macosx : $^O eq 'MSWin32' ? \&clip_win32 : \&clip_unsupported; # ...