#!/usr/bin/perl
use warnings;
use strict;

use HTML::WikiConverter;
use Getopt::Long;

my $dialect = '';
my $base_uri = '';
my $wiki_uri = '';
my $wrap_in_html = 0;

GetOptions(
  'dialect=s'    => \$dialect,
  'base-uri=s'   => \$base_uri,
  'wiki-uri=s'   => \$wiki_uri,
  'wrap-in-html' => \$wrap_in_html,
);

$dialect ||= $ENV{WCDIALECT};
die usage() unless $dialect;

my $wc = new HTML::WikiConverter(
  dialect => $dialect,
  base_uri => $base_uri,
  wiki_uri => $wiki_uri,
  wrap_in_html => $wrap_in_html
);

local $/;
my $html = <>;

print $wc->html2wiki($html), "\n";

sub usage { return <<EOF;
Usage: html2wiki [--dialect <dialect>] [options] [<html-file>]

Options:
  --base-uri      Base URI for relative links
  --wiki-uri      URI fragment for wiki links
  --wrap-in-html  Wrap input in <html> and </html>

The --dialect option is required unless the WCDIALECT environment
variable is set to a dialect.
EOF
}
