Skip to content

Commit

Permalink
Improve click-elem2man --dokuwiki.
Browse files Browse the repository at this point in the history
  • Loading branch information
kohler committed Oct 17, 2017
1 parent 31a6577 commit a8e0fa6
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 31 deletions.
94 changes: 64 additions & 30 deletions doc/click-elem2man
Original file line number Diff line number Diff line change
Expand Up @@ -763,9 +763,9 @@ sub markdownize ($$) {
my(@x) = split(/(^ .*$)/m, $t);
my($o, $i) = '';
for ($i = 0; $i < @x; $i += 2) {
if ($x[$i]) {
if ($x[$i] && $x[$i] ne "\n") {
$o .= markdownize_text($x[$i], $indent);
$o .= "\n" if $o !~ /\n\Z/;
$o =~ s{\n*\z}{\n\n};
}
if ($x[$i+1]) {
$o .= $indent . " " . $x[$i+1] . "\n";
Expand Down Expand Up @@ -804,9 +804,10 @@ sub markdown_do_section ($$$) {
}

if ($name eq 'head1') {
print OUT "\n## ", markdownize($args, ""), " ##\n\n";
$section_name = markdownize($args, "");
print OUT "\n", $section_name, "\n", ("-" x length($section_name)), "\n\n";
} elsif ($name eq 'head2') {
print OUT "\n### ", markdownize($args, ""), " ###\n\n";
print OUT "\n### ", markdownize($args, ""), "\n\n";
} elsif ($name eq 'over') {
if ($args =~ /^\s*(\d+)\s*$/s) {
push @Over, $1;
Expand All @@ -815,18 +816,21 @@ sub markdown_do_section ($$$) {
print STDERR "click-elem2man: $Filename: bad arguments to '=over'\n";
}
} elsif ($name eq 'item') {
print OUT (" " x ($nover ? $nover - 1 : 0)), "* ";
my($bullet) = (" " x ($nover ? $nover - 1 : 0)) . "* ";
my($itemtext) = markdownize($args, "");
if (length($itemtext) <= 40 && $text !~ /\S\n\n+\S/) {
print OUT $itemtext, "";
if (length($itemtext) <= 70) {
my($is_short_item) = $text !~ /\S\n\n+\S/;
print OUT "\n" if !$is_short_item && $markdown_was_short_item;
print OUT $bullet, $itemtext, "\n";
$text =~ s{\A\n+}{};
$text =~ s{\n+\z}{};
$closer = "\n";
$nover = 0;
$markdown_was_short_item = 1;
if ($is_short_item) {
$text =~ s{\n+\z}{};
$closer = "\n";
$nover = 0;
$markdown_was_short_item = 1;
}
} else {
print OUT "\n" if $markdown_was_short_item;
print OUT $itemtext, "\n\n";
print OUT $bullet, $itemtext, "\n\n";
}
} elsif ($name eq 'back') {
my($overarg);
Expand Down Expand Up @@ -864,13 +868,9 @@ sub markdown_do_section ($$$) {
$markdown_was_short_item = 0;
return;
} elsif ($name eq 'name!') {
print OUT <<"EOD;";
# $args Element Documentation #
## NAME ##
**$args** — $text
EOD;
$s = "$args Element Documentation";
print OUT $s, "\n", "=" x length($s), "\n\nNAME\n----\n\n",
"**$args** — $text\n";
return;
} elsif ($name eq 'end!') {
print OUT "\n\nGenerated by click-elem2man from <code>$Filename</code> on $today.\n";
Expand All @@ -886,9 +886,9 @@ sub markdown_elementlist ($@) {
my($sec) = shift @_;
my($t);
if ($sec eq "Alphabetical") {
$t = "## Alphabetically ##\n\n";
$t = "Alphabetical list\n-----------------\n\n";
} else {
$t = "### $sec ###\n\n";
$t = "$sec\n" . ("-" x length($sec)) . "\n\n";
}
foreach $_ (sort { lc($a) cmp lc($b) } @_) {
my($os) = $all_outsections{$_};
Expand Down Expand Up @@ -1335,7 +1335,10 @@ sub process_file ($;$) {
if ($filename ne "<stdin>") {
$filename = "include/$1" if !-e $filename && $filename =~ /^<(.*)>$/s;
$filename = "$PREFIX/$filename" if !-e $filename && defined($PREFIX);
return if !-e $filename;
if (!-e $filename) {
print STDERR "$filename: Not found\n";
return;
}
}
print STDERR "Found $filename\n" if $verbose;
if (!defined($text)) {
Expand Down Expand Up @@ -1685,9 +1688,15 @@ sub markdown_filename_func ($$$) {
if ($destroy) {
();
} elsif ($sec eq $man_section) {
"$directory/" . lc($name) . ".md$gzip";
if ($name eq "elements") {
return "$directory/Elements.md$gzip";
} elsif ($name =~ /^elements-(.*)$/) {
return "$directory/" . ucfirst($1) . "-Elements.md$gzip";
} else {
return "$directory/" . $name . ".md$gzip";
}
} else {
"$directory/" . lc($name) . "-$sec.md$gzip";
return "$directory/" . $name . "-$sec.md$gzip";
}
}

Expand Down Expand Up @@ -1790,8 +1799,13 @@ sub one_summary ($@) {
}
}
my($a) = $name;
$a =~ s{([+\&\#\"\000-\037\177-\377])}{sprintf("%%%02X", ord($1))}eg;
$a =~ tr/ /+/;
if ($output_type eq "markdown") {
$a =~ s{[^a-zA-Z0-9_]+}{-}g;
$a = lc($a);
} else {
$a =~ s{([+\&\#\"\000-\037\177-\377])}{sprintf("%%%02X", ord($1))}eg;
$a =~ tr/ /+/;
}
my($x) = $name;
$x =~ s{ }{&nbsp;}g;
if (@elts) {
Expand Down Expand Up @@ -1822,7 +1836,21 @@ sub write_elementlist ($$) {
return;
}

print OUT <<"EOD;";
if ($output_type eq "markdown") {
my($title);
if ($enamebase eq "elements") {
$title = "Elements";
} elsif ($enamebase eq "elements-click") {
$title = "Click Elements";
} elsif ($enamebase =~ /^elements-(.*)$/) {
$title = ucfirst($1) . " Package Elements";
} else {
$title = ucfirst($title);
}
print OUT $title, "\n", ("=" x length($title)), "\n\n",
"This page lists Click element classes that have manual page documentation.\n\n";
} else {
print OUT <<"EOD;";
.\\" -*- mode: nroff -*-
.\\" Generated by 'click-elem2man'
$nroff_prologue
Expand All @@ -1832,6 +1860,7 @@ $enamebase \- documented Click element classes
.SH "DESCRIPTION"
This page lists all Click element classes that have manual page documentation.
EOD;
}

$Text = "";
%el_generated = ();
Expand All @@ -1848,13 +1877,18 @@ EOD;
one_summary('Miscellaneous', grep { !$el_generated{$_} } @all_outfiles);

my($links) = join("&nbsp;- ", @Links);
print OUT <<"EOD;";
if ($output_type eq "markdown") {
print OUT "**By function:** ", $links, "\n\n";
print OUT "**[Alphabetical list](#alphabetical-list)**\n\n";
} else {
print OUT <<"EOD;";
.\\"html <p><a href="#BY+FUNCTION"><b>By Function</b></a>:
.\\"html $links<br>
.\\"html <a href="#ALPHABETICAL+LIST"><b>Alphabetical List</b></a></p>
.SH \"BY FUNCTION\"
EOD;
}

print OUT ".SH \"BY FUNCTION\"\n";
print OUT $Text;
print OUT &$elementlist_func("Alphabetical", @all_outfiles);

Expand Down
2 changes: 1 addition & 1 deletion doc/mkwebdoc.pl
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ ($)
print OUT eli($esubj[$i]);
}
}

1 while (defined($_ = <IN>) && !/^<!-- \/clickdoc/);
print OUT;
} else {
Expand Down

0 comments on commit a8e0fa6

Please sign in to comment.