File: trac2html

package info (click to toggle)
libtext-trac-perl 0.24-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 712 kB
  • sloc: perl: 1,462; makefile: 10
file content (60 lines) | stat: -rw-r--r-- 1,306 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env perl
use strict;
use warnings;

use Text::Trac ();
use Getopt::Long qw(GetOptions);
use Path::Tiny qw(path);

my ($infile, $outfile);
my $url = '';
my $class;
my $span;
my $id;
my $force;

GetOptions(
	'infile=s'  => \$infile,
	'outfile=s' => \$outfile,
	'url=s'     => \$url,
	'class'     => \$class,
	'span'      => \$span,
	'id'        => \$id,
	'force'     => \$force,
) or usage();
usage() if not $infile or not $outfile;
die "Infile '$infile' does not exist.\n" if not -e $infile;
die "Outfile '$outfile' already exists.\n" if -e $outfile and not $force;

main();
exit;


sub main {
	my $parser = Text::Trac->new(
		trac_url      => $url,
		class         => $class,
		span          => $span,
		id            => $id,
	#	disable_links => [ qw( changeset ticket ) ],
	);
	$parser->parse( path($infile)->slurp_utf8 );
	path($outfile)->spew_utf8( $parser->html );
}


sub usage {
	print <<"END_USAGE";
Usage: $0
    --infile filename     (File in Trac wiki format)
    --outfile filename    (The html file to generate)

    --url http://...      ()
    --class               Include class="" in the HTML tags.
	--span                Include <span></span>
    --id                  Include id="" in the HTML tags.
    --force               Overwrite exisiting html file.
END_USAGE
	exit;
}