#!/usr/bin/env perl
# 
# Convert Emacs' outline-mode text to HTML.
# Copyright (c) 2004-2012, Hiroyuki Ohsaki.
# All rights reserved.
# 
# $Id: outline2html,v 1.12 2023/03/30 08:55:23 ohsaki Exp $
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
# usage: outline2html [file...]
use English;
use strict;
our $item_level = 0;
our $is_slide = 0;
our $first_slide = 1;
sub item_offset {
    my $level = shift;
    return (' ' x (($level - 1) * 2));
}
sub start_item_level {
    my ($level, $str) = @_;
    end_item_level($level);
    while ($item_level < $level) {
	$item_level++;
	print item_offset($item_level) . "
\n";
    }
    if ($level == 0) {
	print "$str
\n\n";
    } elsif ($level == 1) {
	print "$str
\n\n";
    } elsif ($level == 2) {
	print "$str
\n\n";
    } elsif ($level == 3) {
	print "$str
\n\n";
    } else {
	print item_offset($item_level) . "  -  $str\n";
    }
    return $level;
}
sub end_item_level {
    my $level = shift;
    while ($item_level > $level) {
	print item_offset($item_level) . "
 
\n";
	$item_level--;
    }
    return $level;
}
sub dump_header {
    print <<'EOF';
  
EOF
}
sub dump_footer {
    print <<'EOF';
  
EOF
}
dump_header;
while (<>) {
    chomp;
    next if /^-\*-/;
    next if /^\s*$/;
    if (/^\*\s+/) {
	my $str = $POSTMATCH;
	$str =~ s/^[\d.]+\s+//;
	$item_level = start_item_level(0, $str);
    } elsif (/^-\s+/) {
	my $str = $POSTMATCH;
	$item_level = start_item_level(1, $str);
    } elsif (/^  -\s+/) {
	my $str = $POSTMATCH;
	$item_level = start_item_level(2, $str);
    } elsif (/^    -\s+/) {
	my $str = $POSTMATCH;
	$item_level = start_item_level(3, $str);
    } elsif (/^      -\s+/) {
	my $str = $POSTMATCH;
	$item_level = start_item_level(4, $str);
    }
}
$item_level = end_item_level(0);
dump_footer;
__END__
* 論文作成 (日本語)
** 準備
*** 内容
- 研究の背景や目的をきちんと理解し、他の人に説明できるようにしておく。
- 自分のコントリビューションを明確にしておく。
- 目次だけで論文の構成が分かるように工夫する。
- 数値例で使用したパラメータを、どういう理由で選んだのか説明できるように。
- 日本語の論文作成に関する本を、3 冊以上読んで身につける。
論文作成 (日本語)
準備
内容
  - 研究の背景や目的をきちんと理解し、他の人に説明できるようにしておく。
  
 - 自分のコントリビューションを明確にしておく。
  
 - 目次だけで論文の構成が分かるように工夫する。
  
 - 数値例で使用したパラメータを、どういう理由で選んだのか説明できるように。
  
 - 日本語の論文作成に関する本を、3 冊以上読んで身につける。