Skip to content

Instantly share code, notes, and snippets.

@JayDugger
Forked from rlb3/opml2org.pl
Created October 20, 2012 18:08
Show Gist options
  • Save JayDugger/3924231 to your computer and use it in GitHub Desktop.
Save JayDugger/3924231 to your computer and use it in GitHub Desktop.
Convert OPML to org-mode style nested headings, suitable for Confluence or Emacs
#!/usr/bin/perl
# Usage: perl opml2org.pl "My OPML File.opml"
use XML::Parser;
binmode STDOUT, ":utf8";
$xp = new XML::Parser();
$xp->setHandlers(Start => \&start, End => \&end);
$xp->parsefile($ARGV[0]);
$indent = 0;
sub start() {
my ($parser, $name, %attr) = @_;
if ($name eq "outline") {
for($i = 0; $i < $indent; $i++) { print "*"; }
if ($indent > 0) { print " "}
print "$attr{text}\n";
$indent += 1;
}
}
sub end() {
my ($parser, $name) = @_;
if ($name eq "outline") { $indent -= 1; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment