Skip to content

Commit 12ae677

Browse files
daniel-santostorvalds
authored andcommitted
kernel-doc: don't mangle whitespace in Example section
A section with the name "Example" (case-insensitive) has a special meaning to kernel-doc. These sections are output using mono-type fonts. However, leading whitespace is stripped, thus robbing a lot of meaning from this, as indented code examples will be mangled. This patch preserves the leading whitespace for "Example" sections. More accurately, it preserves it for all sections, but removes it later if the section isn't an "Example" section. Signed-off-by: Daniel Santos <daniel.santos@pobox.com> Cc: Randy Dunlap <rdunlap@xenotime.net> Cc: Michal Marek <mmarek@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent e314ba3 commit 12ae677

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

scripts/kernel-doc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,10 @@ my $doc_special = "\@\%\$\&";
281281
my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
282282
my $doc_end = '\*/';
283283
my $doc_com = '\s*\*\s*';
284+
my $doc_com_body = '\s*\* ?';
284285
my $doc_decl = $doc_com . '(\w+)';
285286
my $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)';
286-
my $doc_content = $doc_com . '(.*)';
287+
my $doc_content = $doc_com_body . '(.*)';
287288
my $doc_block = $doc_com . 'DOC:\s*(.*)?';
288289

289290
my %constants;
@@ -460,6 +461,9 @@ sub output_highlight {
460461
# print STDERR "contents af:$contents\n";
461462

462463
foreach $line (split "\n", $contents) {
464+
if (! $output_preformatted) {
465+
$line =~ s/^\s*//;
466+
}
463467
if ($line eq ""){
464468
if (! $output_preformatted) {
465469
print $lineprefix, local_unescape($blankline);
@@ -2085,7 +2089,7 @@ sub process_file($) {
20852089
$descr= $1;
20862090
$descr =~ s/^\s*//;
20872091
$descr =~ s/\s*$//;
2088-
$descr =~ s/\s+/ /;
2092+
$descr =~ s/\s+/ /g;
20892093
$declaration_purpose = xml_escape($descr);
20902094
$in_purpose = 1;
20912095
} else {
@@ -2177,6 +2181,7 @@ sub process_file($) {
21772181
# Continued declaration purpose
21782182
chomp($declaration_purpose);
21792183
$declaration_purpose .= " " . xml_escape($1);
2184+
$declaration_purpose =~ s/\s+/ /g;
21802185
} else {
21812186
$contents .= $1 . "\n";
21822187
}

0 commit comments

Comments
 (0)