#!/usr/bin/env perl # this script is generally responsible for all html postprocessing use v5.39; use utf8; use autodie; use Mojo::DOM; use File::Basename; use open qw( :std :encoding(UTF-8) ); my $LOWDOWN_FLAGS = '--html-titleblock --html-no-head-ids -s --template template.html'; my $content = `lowdown $LOWDOWN_FLAGS $ARGV[0]`; my $dom = Mojo::DOM->new($content); # makes the up button go up a directory my $parent = dirname $ARGV[0]; $parent =~ s/^(?:.+?)(\/.*)/$1/; $parent = dirname $parent if (basename($ARGV[0]) eq 'index.md' or $parent eq 'src'); $dom->at('#go-up')->attr(href => $parent); # give title the same contents as alt if it exists for my $img ($dom->find('img')->each) { my $alt = $img->attr('alt'); $img->attr(title => $alt) if ($alt); } say "$dom";