Created
November 14, 2010 00:03
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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