History

docs: improve the HTML formatting of kerneldoc comments

Make a few changes to cause functions documented by kerneldoc to stand out better in the rendered documentation. Specifically, change kernel-doc to put the description section into a ".. container::" section, then add a bit of CSS to indent that section relative to the function prototype (or struct or enum definition). Tweak a few other CSS parameters while in the neighborhood to improve the formatting.

Jonathan Corbet committed 4 years ago

Commit eaf710c1 parent df198172 files · +48 −22Browse files

Showing the changes to scripts (1 of 2 files). Show all

Unified · Split

scripts/kernel-doc+33−21
@@ -866,48 +866,53 @@ sub output_function_rst(%) { · 865 unmodified lines
866866 print "\n";
867867 }
868868
869− print "**Parameters**\n\n";
869+ #
870+ # Put our descriptive text into a container (thus an HTML <div>) to help
871+ # set the function prototypes apart.
872+ #
873+ print ".. container:: kernelindent\n\n";
870874 $lineprefix = " ";
875+ print $lineprefix . "**Parameters**\n\n";
871876 foreach $parameter (@{$args{'parameterlist'}}) {
872877 my $parameter_name = $parameter;
873878 $parameter_name =~ s/\[.*//;
874879 $type = $args{'parametertypes'}{$parameter};
875880
876881 if ($type ne "") {
877− print "``$type``\n";
882+ print $lineprefix . "``$type``\n";
878883 } else {
879− print "``$parameter``\n";
884+ print $lineprefix . "``$parameter``\n";
880885 }
881886
882887 print_lineno($parameterdesc_start_lines{$parameter_name});
883888
889+ $lineprefix = " ";
884890 if (defined($args{'parameterdescs'}{$parameter_name}) &&
885891 $args{'parameterdescs'}{$parameter_name} ne $undescribed) {
886892 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
887893 } else {
888− print " *undescribed*\n";
894+ print $lineprefix . "*undescribed*\n";
889895 }
896+ $lineprefix = " ";
890897 print "\n";
891898 }
892899
893− $lineprefix = $oldprefix;
894900 output_section_rst(@_);
901+ $lineprefix = $oldprefix;
895902 }
896903
897904 sub output_section_rst(%) {
898905 my %args = %{$_[0]};
899906 my $section;
900907 my $oldprefix = $lineprefix;
901− $lineprefix = "";
902908
903909 foreach $section (@{$args{'sectionlist'}}) {
904− print "**$section**\n\n";
910+ print $lineprefix . "**$section**\n\n";
905911 print_lineno($section_start_lines{$section});
906912 output_highlight_rst($args{'sections'}{$section});
907913 print "\n";
908914 }
909915 print "\n";
910− $lineprefix = $oldprefix;
911916 }
912917
913918 sub output_enum_rst(%) {
@@ -915,6 +920,7 @@ sub output_enum_rst(%) { · 1 unmodified line
915920 my ($parameter);
916921 my $oldprefix = $lineprefix;
917922 my $count;
923+ my $outer;
918924
919925 if ($sphinx_major < 3) {
920926 my $name = "enum " . $args{'enum'};
@@ -924,22 +930,25 @@ sub output_enum_rst(%) { · 3 unmodified lines
924930 print "\n\n.. c:enum:: " . $name . "\n\n";
925931 }
926932 print_lineno($declaration_start_line);
927− $lineprefix = " ";
933+ $lineprefix = " ";
928934 output_highlight_rst($args{'purpose'});
929935 print "\n";
930936
931− print "**Constants**\n\n";
932− $lineprefix = " ";
937+ print ".. container:: kernelindent\n\n";
938+ $outer = $lineprefix . " ";
939+ $lineprefix = $outer . " ";
940+ print $outer . "**Constants**\n\n";
933941 foreach $parameter (@{$args{'parameterlist'}}) {
934− print "``$parameter``\n";
942+ print $outer . "``$parameter``\n";
943+
935944 if ($args{'parameterdescs'}{$parameter} ne $undescribed) {
936945 output_highlight_rst($args{'parameterdescs'}{$parameter});
937946 } else {
938− print " *undescribed*\n";
947+ print $lineprefix . "*undescribed*\n";
939948 }
940949 print "\n";
941950 }
942−
951+ print "\n";
943952 $lineprefix = $oldprefix;
944953 output_section_rst(@_);
945954 }
@@ -982,18 +991,19 @@ sub output_struct_rst(%) { · 36 unmodified lines
982991 }
983992 }
984993 print_lineno($declaration_start_line);
985− $lineprefix = " ";
994+ $lineprefix = " ";
986995 output_highlight_rst($args{'purpose'});
987996 print "\n";
988997
989− print "**Definition**\n\n";
990− print "::\n\n";
998+ print ".. container:: kernelindent\n\n";
999+ print $lineprefix . "**Definition**::\n\n";
9911000 my $declaration = $args{'definition'};
992− $declaration =~ s/\t/ /g;
993− print " " . $args{'type'} . " " . $args{'struct'} . " {\n$declaration };\n\n";
1001+ $lineprefix = $lineprefix . " ";
1002+ $declaration =~ s/\t/$lineprefix/g;
1003+ print $lineprefix . $args{'type'} . " " . $args{'struct'} . " {\n$declaration" . $lineprefix . "};\n\n";
9941004
995− print "**Members**\n\n";
9961005 $lineprefix = " ";
1006+ print $lineprefix . "**Members**\n\n";
9971007 foreach $parameter (@{$args{'parameterlist'}}) {
9981008 ($parameter =~ /^#/) && next;
9991009
@@ -1003,8 +1013,10 @@ sub output_struct_rst(%) { · 3 unmodified lines
10031013 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
10041014 $type = $args{'parametertypes'}{$parameter};
10051015 print_lineno($parameterdesc_start_lines{$parameter_name});
1006− print "``" . $parameter . "``\n";
1016+ print $lineprefix . "``" . $parameter . "``\n";
1017+ $lineprefix = " ";
10071018 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
1019+ $lineprefix = " ";
10081020 print "\n";
10091021 }
10101022 print "\n";

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t