#!/usr/bin/perl # Make a stripped down version of my document for the conference proposal. # Author: Dan Jacobson https://www.jidanni.org/ # Copyright: https://www.gnu.org/licenses/gpl.html # Created: 2024-04-19T08:03:00+0000 # Last-Updated: 2024-04-22T03:42:33+0000 # Update #: 69 # use XML::LibXML; use strict; use warnings q(all); if (0) { my $dom = XML::LibXML->load_xml( string => 'g hi j e u l m' ); print $dom->toString(); for my $node ( $dom->findnodes("//b") ) { my @childnodes = $_->childNodes(); for (@childnodes) { $node->insertBefore( $_, $node ); } } print $dom->toString(); exit; } # https://stackoverflow.com/questions/78352645/xmllibxml-how-to-replace-nodes-with-their-content/78353552 my $dom = XML::LibXML->load_html( location => pop ); for ( $dom->findnodes("//a") ) { my $href = $_->getAttribute("href"); next unless $href =~ m!https://www.openstreetmap.org/#map!; $_->unbindNode(); } my @bads = qw/abs(X)/; for my $node ( $dom->findnodes("//p") ) { my $content = $node->textContent; for (@bads) { unless ( -1 == index( $content, $_ ) ) { $node->unbindNode(); } } } for ( $dom->findnodes("//a") ) { $_->setNodeName("span"); $_->removeAttribute("href"); } for ( $dom->findnodes("//img") ) { my $alt = $_->getAttribute("alt"); my $t = $dom->createTextNode($alt); $_->replaceNode($t); } print $dom->toString();