my $prepared_files = {};
-my $man_target_html = 0;
+my $man_target = 'man';
my $env_stack = [];
my $env_skip = 0;
+sub debug {
+ my $msg = shift;
+
+ return if !$verbose;
+
+ print STDERR "asciidoc-pve: $msg\n";
+}
+
sub push_environment {
my ($env, $skip) = @_;
die "link target is not a manual page" if !defined($section);
- if (0 && $man_target_html) {
+ if ($man_target eq 'html') {
my $target = $link;
$target =~ s/\.adoc//;
$target .= ".$section";
return "link:${target}.html#${blockid}\[$text\]";
- } else {
+ } elsif ($man_target eq 'man') {
my $command = $link;
$command =~ s/\.adoc//;
return "\*${text}\* (man \*${command}\*($section))";
+ } else {
+ die "internal error"
}
}
if ($env eq 'wiki') {
return replace_wiki_xref($blockid, $text);
} elsif ($env eq 'manvolnum') {
- return replace_man_xref($blockid, $text);
+ if (($man_target eq 'man') || ($man_target eq 'html')) {
+ return replace_man_xref($blockid, $text);
+ } elsif ($man_target eq 'wiki') {
+ return replace_wiki_xref($blockid, $text);
+ } else {
+ die "internal error"
+ }
} elsif ($env eq 'default') {
return replace_default_xref($blockid, $text);
} else {
return $prepared_files->{$filename} if defined($prepared_files->{$filename});
- print "PREPARE $filename\n";
+ debug("prepare $filename");
my $dirname = dirname($filename);
my $basename = basename($filename);
if ($line =~ m/^include::(\S+)(\[.*\]\s*)$/) {
my ($fn, $rest) = ($1, $2);
- print "INCLUDE: $fn\n";
+ debug("include $fn");
my $new_fn = prepare_adoc_file($target_env, $fn, $attributes);
print $outfh "include::${new_fn}$rest\n";
my $title = $fileinfo->{titles}->{$env}->{$infile} or
die "unable to get title for '$infile'$env\n";
- print "compile: $title\n";
+ debug("compile $title");
my $leveloffset = 0;
$outfile = $infile;
$outfile =~ s/\.adoc$//;
if ($env eq 'manvolnum') {
- if ($man_target_html) {
+ if (($man_target eq 'html') || ($man_target eq 'wiki')) {
$outfile .= ".$mansection.html";
} else {
$outfile .= ".$mansection";
}
}
- if (($env eq 'manvolnum') && !$man_target_html) {
+ if (($env eq 'manvolnum') && ($man_target eq 'man')) {
# asciidoc /etc/asciidoc/docbook-xsl/manpage.xsl skip REFERENCES
# section like footnotes, so we cannot use a2x.
push @$cmd, $new_infile;
- print "RUN " . join(' ', @$cmd) . "\n";
+ debug("run " . join(' ', @$cmd));
system(@$cmd) == 0 or
die "aciidoc error";
push @$cmd, '-v' if $verbose;
- print "RUN " . join(' ', @$cmd) . "\n";
+ debug("run " . join(' ', @$cmd));
system(@$cmd) == 0 or
die "xmlto error";
my $cmd = ['asciidoc'];
- push @$cmd, '-s' if $env eq 'wiki';
+ push @$cmd, '-s' if ($env eq 'wiki') ||
+ (($env eq 'manvolnum') && ($man_target eq 'wiki'));
foreach my $key (keys %$attributes) {
my $value = $attributes->{$key};
push @$cmd, $new_infile;
- print "RUN " . join(' ', @$cmd) . "\n";
+ debug("run " . join(' ', @$cmd));
system(@$cmd) == 0 or
die "aciidoc error";
} elsif ($clicmd eq 'compile-man-html') {
- $man_target_html = 1;
+ $man_target = 'html';
+
+ eval { compile_asciidoc('manvolnum'); };
+ my $err = $@;
+
+ cleanup();
+
+ die $err if $err;
+
+} elsif ($clicmd eq 'compile-man-wiki') {
+
+ $man_target = 'wiki';
eval { compile_asciidoc('manvolnum'); };
my $err = $@;
die $err if $err;
+} elsif ($clicmd eq 'print-links-json') {
+
+ my $outfile;
+
+ GetOptions("outfile=s" => \$outfile,
+ "verbose" => \$verbose) or
+ die("Error in command line arguments\n");
+
+ scalar(@ARGV) == 0 or
+ die "too many arguments...\n";
+
+ my $data = {};
+
+ foreach my $blockid (sort keys %{$fileinfo->{blockid_target}->{default}}) {
+ my $link = $fileinfo->{blockid_target}->{default}->{$blockid};
+ my $reftitle = $fileinfo->{reftitle}->{default}->{$blockid};
+ my $reftext = $fileinfo->{reftext}->{default}->{$blockid};
+ die "internal error" if $link !~ m/^link:/;
+ $link =~ s/^link://;
+
+ my $file = $fileinfo->{blockid}->{default}->{$blockid};
+ die "internal error - no filename" if ! defined($file);
+ my $title = $fileinfo->{titles}->{default}->{$file} ||
+ die "internal error - no title";
+
+ $data->{$blockid}->{title} = $title;
+ $data->{$blockid}->{link} = $link;
+ my $subtitle = $reftitle || $reftext;
+ $data->{$blockid}->{subtitle} = $subtitle
+ if $subtitle && ($title ne $subtitle);
+ }
+
+ my $res = to_json($data, { pretty => 1, canonical => 1 } );
+
+ if (defined($outfile)) {
+ my $outfh = IO::File->new("$outfile", "w") or
+ die "unable to open temporary file '$outfile'\n";
+
+ print $outfh $res;
+
+ } else {
+
+ print $res;
+ }
+
} else {
die "unknown command '$clicmd'\n";