Skip to content

Instantly share code, notes, and snippets.

@David7ce
Forked from lmmx/opml2html.pl
Created January 25, 2023 00:13
Show Gist options
  • Save David7ce/524ed11dc3c0d02d950a3ae109dc27b8 to your computer and use it in GitHub Desktop.
Save David7ce/524ed11dc3c0d02d950a3ae109dc27b8 to your computer and use it in GitHub Desktop.
OPML to HTML bookmarks file converter, via http://jeremy.zawodny.com/blog/archives/000386.html
#!/usr/bin/perl -w
#
# opml2html.pl, (c) Jeremy Zawodny -- http://jerermy.zawodny.com/blog/
#
# Updated by Michael Radwin (http://www.radwin.org/michael/blog/)
# on Dec 26th, 2003 to include image size attributes and link
# titles.
#
# You may distribute this code freely. It's not rocket science.
#
# Given an OPML file on stdin, produces an XHTML "blgoroll" fragment
# suitable for inclusion on a weblog. Tested with AmphetaDesk and
# Radio UserLand.
#
# Usage: opml2html.pl < foo.opml > bar.html
#
use strict;
use XML::Simple;
use Data::Dumper;
use HTML::Entities;
my $xml;
{
local($/) = undef;
$xml = <>;
}
my $info = XML::Simple::XMLin($xml);
my $data = $info->{body}->{outline};
my @list = sort { lc $a->{title} cmp lc $b->{title} } @$data;
for my $item (@list)
{
my $title = encode_entities($item->{title});
my $h_url = $item->{htmlurl} || $item->{htmlUrl};
my $x_url = $item->{xmlurl} || $item->{xmlUrl};
my $descr = encode_entities($item->{description});
print qq[<p>];
print qq[<a href="$x_url"><img src="xml.gif" border="0" width="36" height="14" /></a>\n];
print qq[<a title="$descr" href="$h_url">$title</a></p>];
print "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment