#!/usr/bin/perl -w
use strict;
use Getopt::Std;
use XML::Simple;
use Data::Dumper qw(Dumper);
# Converts a FreeMind file to a S5 slideshow file
# FreeMind: http://freemind.sourceforge.net/
# S5: http://www.meyerweb.com/eric/tools/s5/
#
# Adaptation of mm2outline.pl from Christian Lemburg
# Author: Vincent Oberle
#
# This program is provided under the GPL.
######################################################
# Usage
#########
my $usage = <<'EOU';
Freemind to S5 convertion
Usage: $0 < freemind.mm > slideshow.html
Options:
-h: print help
-a: slide show author (default "Vincent Oberle")
-l: location and date of the show (default today's date)
-n: notes in intro, like company name (default nothing)
-d: use detail nodes (F6) to generate handouts
EOU
# HTML output
##############
my $html_begin = <<'EOB';
SHOWTITLE
AUTHOR
NOTES
EOB
my $html_slide_begin = <<'EOSB';
SLIDETITLE
EOSB
my $html_end = <<'EOE';
EOE
# Setup
########
my %opts;
getopts('ha:l:n:d', \%opts);
die $usage if $opts{h};
my ($S, $M, $H, $Day, $Month, $Year) = localtime(time);
my $Fixed_Year = $Year + 1900;
my $RealMonth = $Month + 1; if ($RealMonth < 10) { $RealMonth = "0" . $RealMonth; }
if ($Day < 10) { $Day = "0" . $Day; }
my $author = $opts{a} || "Vincent Oberle";
my $locdate = $opts{l} || "$Day/$RealMonth/$Fixed_Year";
my $notes = $opts{n} || "";
my $handouts = $opts{d};
my $NEWLINE = "
";
# Action
#########
my $xs = new XML::Simple();
my $ref = $xs->XMLin(\*STDIN);
die "Could not find mind map in input" unless exists $ref->{node};
my $start = $ref->{node};
my $title = $start->{TEXT};
$html_begin =~ s/SHOWTITLE/$title/g;
$html_begin =~ s/LOCATIONDATE/$locdate/g;
$html_begin =~ s/AUTHOR/$author/g;
$html_begin =~ s/NOTES/$notes/g;
print $html_begin;
my $level = 0;
my $hand = "";
process_children($start);
print $html_end;
# Subs
#######
sub process_node {
my ($node) = @_;
my $tmp;
if ($level == 1) {
$tmp = $html_slide_begin;
$tmp =~ s/SLIDETITLE/$node->{TEXT}/g;
print $tmp;
process_children($node);
}
else {
if (($handouts) && ($node->{COLOR}) && ($node->{COLOR} eq '#999999')) {
if ($hand) { $hand = "$hand
\n" . "$node->{TEXT}"; }
else { $hand = $node->{TEXT}; }
}
else {
print "
";
print $node->{TEXT};
if (not is_leaf($node)) {
print "\n";
process_children($node);
print "
\n";
}
print "\n";
}
}
if ($level == 1) {
print "\n";
if (($handouts) && ($hand)) {
print "
\n$hand\n
\n";
$hand = "";
}
print "
\n";
}
}
sub process_children {
my ($node) = @_;
$level++;
if (ref($node->{node}) eq "ARRAY") {
for my $child (@{$node->{node}}) {
process_node($child);
}
} else {
my $child = $node->{node};
process_node($child);
}
$level--;
}
sub is_leaf {
my ($node) = @_;
return not exists $node->{node};
}
sub is_paragraph_leaf {
my ($node) = @_;
# define: paragraph leaf = leaf with text that contains newlines
return is_leaf($node) && $node->{TEXT} =~ /$NEWLINE/;
}