diff options
| author | Dan Luedtke <mail@danrl.de> | 2012-08-12 04:46:15 -0400 |
|---|---|---|
| committer | Michal Marek <mmarek@suse.cz> | 2012-08-31 09:34:39 -0400 |
| commit | 1b40c1944db445c1de1c47ffd8cd426167f488e8 (patch) | |
| tree | 8804c595ead5e63512ef61ab18952e8489f32862 | |
| parent | 0d7614f09c1ebdbaa1599a5aba7593f147bf96ee (diff) | |
scripts/kernel-doc: added support for html5
New output option html5 writes validating HTML5 and adds
CSS classes ready to be selected by third-party stylesheets.
HTML ids have been added to block-level elements "article" for
direct reference of particular objects via URL.
Signed-off-by: Dan Luedtke <mail@danrl.de>
Acked-by: Randy Dunlap <rdunlap@xenotime.net>
Signed-off-by: Michal Marek <mmarek@suse.cz>
| -rwxr-xr-x | scripts/kernel-doc | 273 |
1 files changed, 266 insertions, 7 deletions
diff --git a/scripts/kernel-doc b/scripts/kernel-doc index 9b0c0b8b4ab..97e037aa97a 100755 --- a/scripts/kernel-doc +++ b/scripts/kernel-doc | |||
| @@ -6,6 +6,7 @@ use strict; | |||
| 6 | ## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ## | 6 | ## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ## |
| 7 | ## Copyright (C) 2001 Simon Huggins ## | 7 | ## Copyright (C) 2001 Simon Huggins ## |
| 8 | ## Copyright (C) 2005-2012 Randy Dunlap ## | 8 | ## Copyright (C) 2005-2012 Randy Dunlap ## |
| 9 | ## Copyright (C) 2012 Dan Luedtke ## | ||
| 9 | ## ## | 10 | ## ## |
| 10 | ## #define enhancements by Armin Kuster <akuster@mvista.com> ## | 11 | ## #define enhancements by Armin Kuster <akuster@mvista.com> ## |
| 11 | ## Copyright (c) 2000 MontaVista Software, Inc. ## | 12 | ## Copyright (c) 2000 MontaVista Software, Inc. ## |
| @@ -35,6 +36,8 @@ use strict; | |||
| 35 | # Small fixes (like spaces vs. \s in regex) | 36 | # Small fixes (like spaces vs. \s in regex) |
| 36 | # -- Tim Jansen <tim@tjansen.de> | 37 | # -- Tim Jansen <tim@tjansen.de> |
| 37 | 38 | ||
| 39 | # 25/07/2012 - Added support for HTML5 | ||
| 40 | # -- Dan Luedtke <mail@danrl.de> | ||
| 38 | 41 | ||
| 39 | # | 42 | # |
| 40 | # This will read a 'c' file and scan for embedded comments in the | 43 | # This will read a 'c' file and scan for embedded comments in the |
| @@ -44,12 +47,16 @@ use strict; | |||
| 44 | # Note: This only supports 'c'. | 47 | # Note: This only supports 'c'. |
| 45 | 48 | ||
| 46 | # usage: | 49 | # usage: |
| 47 | # kernel-doc [ -docbook | -html | -text | -man | -list ] [ -no-doc-sections ] | 50 | # kernel-doc [ -docbook | -html | -html5 | -text | -man | -list ] |
| 48 | # [ -function funcname [ -function funcname ...] ] c file(s)s > outputfile | 51 | # [ -no-doc-sections ] |
| 52 | # [ -function funcname [ -function funcname ...] ] | ||
| 53 | # c file(s)s > outputfile | ||
| 49 | # or | 54 | # or |
| 50 | # [ -nofunction funcname [ -function funcname ...] ] c file(s)s > outputfile | 55 | # [ -nofunction funcname [ -function funcname ...] ] |
| 56 | # c file(s)s > outputfile | ||
| 51 | # | 57 | # |
| 52 | # Set output format using one of -docbook -html -text or -man. Default is man. | 58 | # Set output format using one of -docbook -html -html5 -text or -man. |
| 59 | # Default is man. | ||
| 53 | # The -list format is for internal use by docproc. | 60 | # The -list format is for internal use by docproc. |
| 54 | # | 61 | # |
| 55 | # -no-doc-sections | 62 | # -no-doc-sections |
| @@ -182,6 +189,14 @@ my $local_lt = "\\\\\\\\lt:"; | |||
| 182 | my $local_gt = "\\\\\\\\gt:"; | 189 | my $local_gt = "\\\\\\\\gt:"; |
| 183 | my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>" | 190 | my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>" |
| 184 | 191 | ||
| 192 | # html version 5 | ||
| 193 | my %highlights_html5 = ( $type_constant, "<span class=\"const\">\$1</span>", | ||
| 194 | $type_func, "<span class=\"func\">\$1</span>", | ||
| 195 | $type_struct_xml, "<span class=\"struct\">\$1</span>", | ||
| 196 | $type_env, "<span class=\"env\">\$1</span>", | ||
| 197 | $type_param, "<span class=\"param\">\$1</span>" ); | ||
| 198 | my $blankline_html5 = $local_lt . "br /" . $local_gt; | ||
| 199 | |||
| 185 | # XML, docbook format | 200 | # XML, docbook format |
| 186 | my %highlights_xml = ( "([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>", | 201 | my %highlights_xml = ( "([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>", |
| 187 | $type_constant, "<constant>\$1</constant>", | 202 | $type_constant, "<constant>\$1</constant>", |
| @@ -309,6 +324,10 @@ while ($ARGV[0] =~ m/^-(.*)/) { | |||
| 309 | $output_mode = "html"; | 324 | $output_mode = "html"; |
| 310 | %highlights = %highlights_html; | 325 | %highlights = %highlights_html; |
| 311 | $blankline = $blankline_html; | 326 | $blankline = $blankline_html; |
| 327 | } elsif ($cmd eq "-html5") { | ||
| 328 | $output_mode = "html5"; | ||
| 329 | %highlights = %highlights_html5; | ||
| 330 | $blankline = $blankline_html5; | ||
| 312 | } elsif ($cmd eq "-man") { | 331 | } elsif ($cmd eq "-man") { |
| 313 | $output_mode = "man"; | 332 | $output_mode = "man"; |
| 314 | %highlights = %highlights_man; | 333 | %highlights = %highlights_man; |
| @@ -351,10 +370,11 @@ while ($ARGV[0] =~ m/^-(.*)/) { | |||
| 351 | # continue execution near EOF; | 370 | # continue execution near EOF; |
| 352 | 371 | ||
| 353 | sub usage { | 372 | sub usage { |
| 354 | print "Usage: $0 [ -v ] [ -docbook | -html | -text | -man | -list ]\n"; | 373 | print "Usage: $0 [ -docbook | -html | -html5 | -text | -man | -list ]\n"; |
| 355 | print " [ -no-doc-sections ]\n"; | 374 | print " [ -no-doc-sections ]\n"; |
| 356 | print " [ -function funcname [ -function funcname ...] ]\n"; | 375 | print " [ -function funcname [ -function funcname ...] ]\n"; |
| 357 | print " [ -nofunction funcname [ -nofunction funcname ...] ]\n"; | 376 | print " [ -nofunction funcname [ -nofunction funcname ...] ]\n"; |
| 377 | print " [ -v ]\n"; | ||
| 358 | print " c source file(s) > outputfile\n"; | 378 | print " c source file(s) > outputfile\n"; |
| 359 | print " -v : verbose output, more warnings & other info listed\n"; | 379 | print " -v : verbose output, more warnings & other info listed\n"; |
| 360 | exit 1; | 380 | exit 1; |
| @@ -448,7 +468,8 @@ sub output_highlight { | |||
| 448 | # confess "output_highlight got called with no args?\n"; | 468 | # confess "output_highlight got called with no args?\n"; |
| 449 | # } | 469 | # } |
| 450 | 470 | ||
| 451 | if ($output_mode eq "html" || $output_mode eq "xml") { | 471 | if ($output_mode eq "html" || $output_mode eq "html5" || |
| 472 | $output_mode eq "xml") { | ||
| 452 | $contents = local_unescape($contents); | 473 | $contents = local_unescape($contents); |
| 453 | # convert data read & converted thru xml_escape() into &xyz; format: | 474 | # convert data read & converted thru xml_escape() into &xyz; format: |
| 454 | $contents =~ s/\\\\\\/\&/g; | 475 | $contents =~ s/\\\\\\/\&/g; |
| @@ -458,6 +479,11 @@ sub output_highlight { | |||
| 458 | die $@ if $@; | 479 | die $@ if $@; |
| 459 | # print STDERR "contents af:$contents\n"; | 480 | # print STDERR "contents af:$contents\n"; |
| 460 | 481 | ||
| 482 | # strip whitespaces when generating html5 | ||
| 483 | if ($output_mode eq "html5") { | ||
| 484 | $contents =~ s/^\s+//; | ||
| 485 | $contents =~ s/\s+$//; | ||
| 486 | } | ||
| 461 | foreach $line (split "\n", $contents) { | 487 | foreach $line (split "\n", $contents) { |
| 462 | if ($line eq ""){ | 488 | if ($line eq ""){ |
| 463 | print $lineprefix, local_unescape($blankline); | 489 | print $lineprefix, local_unescape($blankline); |
| @@ -473,7 +499,7 @@ sub output_highlight { | |||
| 473 | } | 499 | } |
| 474 | } | 500 | } |
| 475 | 501 | ||
| 476 | #output sections in html | 502 | # output sections in html |
| 477 | sub output_section_html(%) { | 503 | sub output_section_html(%) { |
| 478 | my %args = %{$_[0]}; | 504 | my %args = %{$_[0]}; |
| 479 | my $section; | 505 | my $section; |
| @@ -633,6 +659,239 @@ sub output_blockhead_html(%) { | |||
| 633 | print "<hr>\n"; | 659 | print "<hr>\n"; |
| 634 | } | 660 | } |
| 635 | 661 | ||
| 662 | # output sections in html5 | ||
| 663 | sub output_section_html5(%) { | ||
| 664 | my %args = %{$_[0]}; | ||
| 665 | my $section; | ||
| 666 | |||
| 667 | foreach $section (@{$args{'sectionlist'}}) { | ||
| 668 | print "<section>\n"; | ||
| 669 | print "<h1>$section</h1>\n"; | ||
| 670 | print "<p>\n"; | ||
| 671 | output_highlight($args{'sections'}{$section}); | ||
| 672 | print "</p>\n"; | ||
| 673 | print "</section>\n"; | ||
| 674 | } | ||
| 675 | } | ||
| 676 | |||
| 677 | # output enum in html5 | ||
| 678 | sub output_enum_html5(%) { | ||
| 679 | my %args = %{$_[0]}; | ||
| 680 | my ($parameter); | ||
| 681 | my $count; | ||
| 682 | my $html5id; | ||
| 683 | |||
| 684 | $html5id = $args{'enum'}; | ||
| 685 | $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; | ||
| 686 | print "<article class=\"enum\" id=\"enum:". $html5id . "\">"; | ||
| 687 | print "<h1>enum " . $args{'enum'} . "</h1>\n"; | ||
| 688 | print "<ol class=\"code\">\n"; | ||
| 689 | print "<li>"; | ||
| 690 | print "<span class=\"keyword\">enum</span> "; | ||
| 691 | print "<span class=\"identifier\">" . $args{'enum'} . "</span> {"; | ||
| 692 | print "</li>\n"; | ||
| 693 | $count = 0; | ||
| 694 | foreach $parameter (@{$args{'parameterlist'}}) { | ||
| 695 | print "<li class=\"indent\">"; | ||
| 696 | print "<span class=\"param\">" . $parameter . "</span>"; | ||
| 697 | if ($count != $#{$args{'parameterlist'}}) { | ||
| 698 | $count++; | ||
| 699 | print ","; | ||
| 700 | } | ||
| 701 | print "</li>\n"; | ||
| 702 | } | ||
| 703 | print "<li>};</li>\n"; | ||
| 704 | print "</ol>\n"; | ||
| 705 | |||
| 706 | print "<section>\n"; | ||
| 707 | print "<h1>Constants</h1>\n"; | ||
| 708 | print "<dl>\n"; | ||
| 709 | foreach $parameter (@{$args{'parameterlist'}}) { | ||
| 710 | print "<dt>" . $parameter . "</dt>\n"; | ||
| 711 | print "<dd>"; | ||
| 712 | output_highlight($args{'parameterdescs'}{$parameter}); | ||
| 713 | print "</dd>\n"; | ||
| 714 | } | ||
| 715 | print "</dl>\n"; | ||
| 716 | print "</section>\n"; | ||
| 717 | output_section_html5(@_); | ||
| 718 | print "</article>\n"; | ||
| 719 | } | ||
| 720 | |||
| 721 | # output typedef in html5 | ||
| 722 | sub output_typedef_html5(%) { | ||
| 723 | my %args = %{$_[0]}; | ||
| 724 | my ($parameter); | ||
| 725 | my $count; | ||
| 726 | my $html5id; | ||
| 727 | |||
| 728 | $html5id = $args{'typedef'}; | ||
| 729 | $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; | ||
| 730 | print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n"; | ||
| 731 | print "<h1>typedef " . $args{'typedef'} . "</h1>\n"; | ||
| 732 | |||
| 733 | print "<ol class=\"code\">\n"; | ||
| 734 | print "<li>"; | ||
| 735 | print "<span class=\"keyword\">typedef</span> "; | ||
| 736 | print "<span class=\"identifier\">" . $args{'typedef'} . "</span>"; | ||
| 737 | print "</li>\n"; | ||
| 738 | print "</ol>\n"; | ||
| 739 | output_section_html5(@_); | ||
| 740 | print "</article>\n"; | ||
