|There's more than one way to do things|
Printer friendly pages on perlmonks.by Dog and Pony (Priest)
|on Jun 04, 2002 at 12:35 UTC||Need Help??|
Yes, I know, I know - the subject has long since been beaten thouroughly to death, at least some of you will think so.
On certain places on this site, there is also the possibility to say &displaytype=raw, as described among other places here and here. On the interesting places though, such as normal nodes, it usually bombs out with a "500 internal error".
Well, anyhow, I once again had reason to print something from this site, to study somewhere else. Then I started to wonder... exactly how hard would it be to simply strip out the parts of the page that were unwanted? As it turned out, it was a 10 minute job, since I cheated and used regexps instead of a real parser - but save for some HTML changes (which of course are bound to happen sooner or later), it seems to work just fine. I'm just waiting to hear it break badly. :)
To demonstrate this, I put together a little CGI that one can use to get what I consider the parts of the page that I want to print, and the rest is stripped out. You can try it here, and see the code below. As an extra thought, I added possibility to paste some CSS into the page too, if you want nice boxes around code blocks or something like that. Another option would have been to forward username/password combos to retain your own personal CSS if any, but that would fast be quite a question of trust... :)
Another option that are available is of course http://perlmonks.thepen.com, which already features a pretty stripped version of the site, although I do not like the huge part at the top of it (for printing, that is).
Well, so what was the point? I'm not sure. :) For one thing, I still want the feature where I could click a link to get a printerfriendly version of any page. If nothing else, with this I can demonstrate what parts I think should be taken out on that page, and which should be still there. If this would be implemented on perlmonks, it would most likely be more wise to not produce those parts, rather than remove after producing, so this code is probably worthless. On the other hand, I got to spend some time coding on something pointless, which is one of my top three hobbies (the other two is most probably beer), and I got something to post here. Fun is important. :)
I am, however gonna leave the code up (and you can get it from here as well), so as long as it doesn't break, one can solve the problems themselves with this. But of course it would be really cool if anyone actually could use it for something. :) For now, I will use it to get my printouts when needed...
You have moved into a dark place.
It is pitch black. You are likely to be eaten by a grue.