1212my $debug ;
1313my $prefix =" Documentation/ABI" ;
1414
15+ #
16+ # If true, assumes that the description is formatted with ReST
17+ #
18+ my $description_is_rst = 0;
19+
1520GetOptions(
1621 " debug|d+" => \$debug ,
22+ " rst-source!" => \$description_is_rst ,
1723 " dir=s" => \$prefix ,
1824 ' help|?' => \$help ,
1925 man => \$man
@@ -137,14 +143,15 @@ sub parse_abi {
137143 next ;
138144 }
139145 if ($tag eq " description" ) {
140- next if ($content =~ m / ^\s *$ / );
141- if ($content =~ m / ^(\s *)(.*)/ ) {
142- my $new_content = $2 ;
143- $space = $new_tag . $sep . $1 ;
144- while ($space =~ s /\t +/ ' ' x (length($& ) * 8 - length($` ) % 8)/ e ) {}
145- $space =~ s / ./ / g ;
146- $data {$what }-> {$tag } .= " $new_content \n " ;
146+ # Preserve initial spaces for the first line
147+ $content = ' ' x length ($new_tag ) . $sep . $content ;
148+ $content =~ s ,^(\s *):,$1 ,;
149+ if ($content =~ m / ^(\s *)(.*)$ / ) {
150+ $space = $1 ;
151+ $content = $2 ;
147152 }
153+ while ($space =~ s /\t +/ ' ' x (length($& ) * 8 - length($` ) % 8)/ e ) {}
154+ $data {$what }-> {$tag } .= $content ;
148155 } else {
149156 $data {$what }-> {$tag } = $content ;
150157 }
@@ -160,11 +167,15 @@ sub parse_abi {
160167
161168 if ($tag eq " description" ) {
162169 if (!$data {$what }-> {description }) {
163- next if ( m / ^ \s * \n / ) ;
170+ s / ^($space) // ;
164171 if (m / ^(\s *)(.*)/ ) {
165- $space = $1 ;
166- while ($space =~ s /\t +/ ' ' x (length($& ) * 8 - length($` ) % 8)/ e ) {}
167- $data {$what }-> {$tag } .= " $2 \n " ;
172+ my $sp = $1 ;
173+ while ($sp =~ s /\t +/ ' ' x (length($& ) * 8 - length($` ) % 8)/ e ) {}
174+ my $content = " $sp$2 " ;
175+
176+ $content =~ s / ^($space)// ;
177+
178+ $data {$what }-> {$tag } .= " $content " ;
168179 }
169180 } else {
170181 my $content = $_ ;
@@ -274,23 +285,27 @@ sub output_rest {
274285 print " Defined on file :ref:`$file <$fileref >`\n\n " if ($type ne " File" );
275286
276287 my $desc = $data {$what }-> {description };
277- $desc =~ s / ^\s +// ;
278-
279- # Remove title markups from the description, as they won't work
280- $desc =~ s /\n [\-\*\=\^\~ ]+\n / \n / g ;
281288
282289 if (!($desc =~ / ^\s *$ / )) {
283- if ($desc =~ m /\:\n / || $desc =~ m /\n [\t ] +/ || $desc =~ m /[\x00 -\x08\x0b -\x1f\x7b -\xff ] / ) {
284- # put everything inside a code block
285- $desc =~ s /\n / \n / g ;
286-
287- print " ::\n\n " ;
288- print " $desc \n\n " ;
290+ if ($description_is_rst ) {
291+ print " $desc \n\n " ;
289292 } else {
290- # Escape any special chars from description
291- $desc =~s / ([\x00 -\x08\x0b -\x1f\x21 -\x2a\x2d\x2f\x3c -\x40\x5c\x5e -\x60\x7b -\xff ])/ \\ $1 / g ;
293+ $desc =~ s / ^\s +// ;
292294
293- print " $desc \n\n " ;
295+ # Remove title markups from the description, as they won't work
296+ $desc =~ s /\n [\-\*\=\^\~ ]+\n / \n\n / g ;
297+
298+ if ($desc =~ m /\:\n / || $desc =~ m /\n [\t ] +/ || $desc =~ m /[\x00 -\x08\x0b -\x1f\x7b -\xff ] / ) {
299+ # put everything inside a code block
300+ $desc =~ s /\n / \n / g ;
301+
302+ print " ::\n\n " ;
303+ print " $desc \n\n " ;
304+ } else {
305+ # Escape any special chars from description
306+ $desc =~s / ([\x00 -\x08\x0b -\x1f\x21 -\x2a\x2d\x2f\x3c -\x40\x5c\x5e -\x60\x7b -\xff ])/ \\ $1 / g ;
307+ print " $desc \n\n " ;
308+ }
294309 }
295310 } else {
296311 print " DESCRIPTION MISSING for $what \n\n " if (!$data {$what }-> {is_file });
@@ -382,7 +397,7 @@ =head1 NAME
382397
383398=head1 SYNOPSIS
384399
385- B<abi_book.pl > [--debug] [--man] [--help] [--dir=<dir>] <COMAND> [<ARGUMENT>]
400+ B<abi_book.pl > [--debug] [--man] [--help] --[(no-)rst-source] [--dir=<dir>] <COMAND> [<ARGUMENT>]
386401
387402Where <COMMAND> can be:
388403
@@ -405,6 +420,13 @@ =head1 OPTIONS
405420Changes the location of the ABI search. By default, it uses
406421the Documentation/ABI directory.
407422
423+ =item B<--rst-source > and B<--no-rst-source >
424+
425+ The input file may be using ReST syntax or not. Those two options allow
426+ selecting between a rst-compliant source ABI (--rst-source), or a
427+ plain text that may be violating ReST spec, so it requres some escaping
428+ logic (--no-rst-source).
429+
408430=item B<--debug >
409431
410432Put the script in verbose mode, useful for debugging. Can be called multiple
0 commit comments