Fixes for the online docs

This commit is contained in:
Brian Fraser
2013-03-20 13:14:37 -03:00
parent c0b59501f0
commit 5c30f5517e
4 changed files with 40 additions and 28 deletions

View File

@@ -1,19 +0,0 @@
#!/usr/bin/env bash
die() {
echo "$1" >&2
exit 1
}
file=$1
from=$2
to=$3
start_line=$(grep --line-number "$from" $file | cut -d':' -f1)
if [ -z "$start_line" ]; then
die "Cannot find $from in $file"
fi
tail -n +$start_line $file | awk "BEGIN { getline; print \$0 } /$to/ { exit } { print }"
exit $?

View File

@@ -11,6 +11,8 @@ use Pod::POM::View::Restructured;
my $input_file = shift @ARGV or die "Need an input file";
my $nofix = scalar @ARGV;
my $tool = basename($input_file);
open my $in_fh, q{<:encoding(UTF-8)}, $input_file
@@ -44,6 +46,11 @@ my $section = '';
my $fixed_output = '';
while (my $para = <$in>) {
if ( $nofix ) {
$fixed_output .= $para;
next;
}
next if $para =~ m/^\.\. highlight:: perl/;
$in_code_block = $para =~ m/^\s{2,}/ ? 1 : 0;
@@ -77,6 +84,7 @@ while (my $para = <$in>) {
$para =~ s/^[ ]+$//mg;
$para =~ s/^\n\n/\n/mg;
$para =~ s/code-block:: bash(\s+)CREATE/code-block:: sql$1CREATE/sg;
$para =~ s/\*\*:program/** :program/g;
if ( ($section || '') eq 'OUTPUT' ) {
$para =~ s/^([A-Z_]+)\n\n/$1\n/;
}
@@ -86,7 +94,12 @@ while (my $para = <$in>) {
close $in;
if ($nofix) {
print $fixed_output;
}
else {
print $header . $fixed_output;
}
sub format_links {
if ( my ($label, $url) = split /\|/, $_[0] ) {

View File

@@ -5683,6 +5683,8 @@ use Pod::POM::View::Restructured;
my $input_file = shift @ARGV or die "Need an input file";
my $nofix = scalar @ARGV;
my $tool = basename($input_file);
open my $in_fh, q{<:encoding(UTF-8)}, $input_file
@@ -5716,6 +5718,11 @@ my $section = '';
my $fixed_output = '';
while (my $para = <$in>) {
if ( $nofix ) {
$fixed_output .= $para;
next;
}
next if $para =~ m/^\.\. highlight:: perl/;
$in_code_block = $para =~ m/^\s{2,}/ ? 1 : 0;
@@ -5749,6 +5756,7 @@ while (my $para = <$in>) {
$para =~ s/^[ ]+$//mg;
$para =~ s/^\n\n/\n/mg;
$para =~ s/code-block:: bash(\s+)CREATE/code-block:: sql$1CREATE/sg;
$para =~ s/\*\*:program/** :program/g;
if ( ($section || '') eq 'OUTPUT' ) {
$para =~ s/^([A-Z_]+)\n\n/$1\n/;
}
@@ -5758,7 +5766,12 @@ while (my $para = <$in>) {
close $in;
if ($nofix) {
print $fixed_output;
}
else {
print $header . $fixed_output;
}
sub format_links {
if ( my ($label, $url) = split /\|/, $_[0] ) {

View File

@@ -72,17 +72,17 @@ fix_html () {
my $f = shift;
my $tool = basename($f);
$tool =~ s/\.html//;
my $out = do { open my $fh, '<', $f or die $!; local $/; <$fh> };
my $out = do { open my $fh, q{<}, $f or die "$f: $!"; local $/; <$fh> };
$out =~ s{
\Q<dt id="\E(cmdoption-$tool--)\Q">\E\s*
\Q<tt class="descname">--</tt><tt class="descclassname">\E([^<]+)
\Q</tt><a class="headerlink" href="\E[^"]+"
}{<dt id="$1$2">
<tt class="descname">--$2</tt><tt class="descclassname"></tt><a class="headerlink" href="#$1$2"}xg;
open my $fh, '>', $f or die "Cannot open $f for writing: $!";
open my $fh, q{>}, $f or die "Cannot open $f for writing: $!";
print { $f } $out;
close $fh or die "Cannot close $f: $!";
' $RST_DIR/html/$name.html
' "$RST_DIR/html/$name.html"
}
write_rst() {
@@ -120,10 +120,15 @@ write_sections() {
filename=$(echo $section | sed -e 's/,//g' -e 's/[()]//g' | tr "[:upper:]" "[:lower:]");
# Extract the section as POD.
$BRANCH/util/extract-text $DOCS_DIR/percona-toolkit.pod "^=head1 $header" "^=head1|=cut" > /tmp/$filename.pod
local start_line=$(grep --line-number "^=head1 $header" $DOCS_DIR/percona-toolkit.pod | cut -d':' -f1)
if [ -z "$start_line" ]; then
die "Cannot find $from in $DOCS_DIR/percona-toolkit.pod"
fi
tail -n +$start_line $DOCS_DIR/percona-toolkit.pod | awk "BEGIN { getline; print \$0 } /^=head1|=cut/ { exit } { print }" > /tmp/$filename.pod
# Convert POD to RST and remove all the Perl highlight blocks.
$BRANCH/util/pod2rst-fixed.packed /tmp/$filename.pod | sed -e 's/.. highlight:: perl//g' > /tmp/$filename.tmp
$BRANCH/util/pod2rst-fixed.packed /tmp/$filename.pod --no-fix | sed -e 's/.. highlight:: perl//g' > /tmp/$filename.tmp
# Remove extra blank lines.
cat -s /tmp/$filename.tmp > $RST_DIR/$filename.rst