Skip to content

Instantly share code, notes, and snippets.

@alandipert
Created November 14, 2010 00:03
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save alandipert/675767 to your computer and use it in GitHub Desktop.
Save alandipert/675767 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