Change the description parsing logic in rst mode in order to parse it line per line. The end result is the same, but doing line per line allows to add some code to escape literal blocks when seeking for cross-references.
Unified · Split
| @@ -381,34 +381,41 @@ sub output_rest { · 380 unmodified lines | ||
| 381 | 381 | |
| 382 | 382 | # Enrich text by creating cross-references |
| 383 | 383 | |
| 384 | − $desc =~ s,Documentation/(?!devicetree)(\S+)\.rst,:doc:`/$1`,g; | |
| 385 | − | |
| 386 | − my @matches = $desc =~ m,Documentation/ABI/([\w\/\-]+),g; | |
| 387 | − foreach my $f (@matches) { | |
| 388 | − my $xref = $f; | |
| 389 | − my $path = $f; | |
| 390 | − $path =~ s,.*/(.*/.*),$1,;; | |
| 391 | − $path =~ s,[/\-],_,g;; | |
| 392 | − $xref .= " <abi_file_" . $path . ">"; | |
| 393 | − $desc =~ s,\bDocumentation/ABI/$f\b,:ref:`$xref`,g; | |
| 394 | − } | |
| 384 | + my $new_desc = ""; | |
| 385 | + open(my $fh, "+<", \$desc); | |
| 386 | + while (my $d = <$fh>) { | |
| 387 | + $d =~ s,Documentation/(?!devicetree)(\S+)\.rst,:doc:`/$1`,g; | |
| 388 | + | |
| 389 | + my @matches = $d =~ m,Documentation/ABI/([\w\/\-]+),g; | |
| 390 | + foreach my $f (@matches) { | |
| 391 | + my $xref = $f; | |
| 392 | + my $path = $f; | |
| 393 | + $path =~ s,.*/(.*/.*),$1,;; | |
| 394 | + $path =~ s,[/\-],_,g;; | |
| 395 | + $xref .= " <abi_file_" . $path . ">"; | |
| 396 | + $d =~ s,\bDocumentation/ABI/$f\b,:ref:`$xref`,g; | |
| 397 | + } | |
| 395 | 398 | |
| 396 | − # Seek for cross reference symbols like /sys/... | |
| 397 | − @matches = $desc =~ m/$xref_match/g; | |
| 399 | + # Seek for cross reference symbols like /sys/... | |
| 400 | + @matches = $d =~ m/$xref_match/g; | |
| 398 | 401 | |
| 399 | − foreach my $s (@matches) { | |
| 400 | − next if (!($s =~ m,/,)); | |
| 401 | − if (defined($data{$s}) && defined($data{$s}->{label})) { | |
| 402 | − my $xref = $s; | |
| 402 | + foreach my $s (@matches) { | |
| 403 | + next if (!($s =~ m,/,)); | |
| 404 | + if (defined($data{$s}) && defined($data{$s}->{label})) { | |
| 405 | + my $xref = $s; | |
| 403 | 406 | |
| 404 | − $xref =~ s/$symbols/\\$1/g; | |
| 405 | − $xref = ":ref:`$xref <" . $data{$s}->{label} . ">`"; | |
| 407 | + $xref =~ s/$symbols/\\$1/g; | |
| 408 | + $xref = ":ref:`$xref <" . $data{$s}->{label} . ">`"; | |
| 406 | 409 | |
| 407 | − $desc =~ s,$start$s$bondary,$1$xref$2,g; | |
| 410 | + $d =~ s,$start$s$bondary,$1$xref$2,g; | |
| 411 | + } | |
| 408 | 412 | } |
| 413 | + $new_desc .= $d; | |
| 409 | 414 | } |
| 415 | + close $fh; | |
| 416 | + | |
| 410 | 417 | |
| 411 | − print "$desc\n\n"; | |
| 418 | + print "$new_desc\n\n"; | |
| 412 | 419 | } else { |
| 413 | 420 | $desc =~ s/^\s+//; |
| 414 | 421 | |