I use this in my elinks hooks.pl to indent hn comments.
use strict;
use warnings;
use Encode;
use Mojo::DOM;
sub pre_format_html_hook {
my $url = shift;
my $html = Mojo::DOM->new(decode_utf8(shift));
if ($url =~ 'news\.ycombinator\.com') {
$html->find('img[src="s.gif"]')->each(sub { my $e = shift;
my $w = $e->attr('width');
my $ns = ' ' x ( $w / 10 );
$e->replace($ns); });
}
return $html;
}