linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab@kernel.org>
To: Matthew Wilcox <willy@infradead.org>
Cc: Markus Heiser <markus.heiser@darmarit.de>,
	Randy Dunlap <rdunlap@infradead.org>,
	"linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>,
	Jonathan Corbet <corbet@lwn.net>
Subject: Re: excess bolding in html
Date: Fri, 30 Oct 2020 15:00:19 +0100	[thread overview]
Message-ID: <20201030150019.1cc6db7d@coco.lan> (raw)
In-Reply-To: <20201030125313.GH27442@casper.infradead.org>

Em Fri, 30 Oct 2020 12:53:13 +0000
Matthew Wilcox <willy@infradead.org> escreveu:

> On Fri, Oct 30, 2020 at 01:28:59PM +0100, Markus Heiser wrote:
> > Am 30.10.20 um 12:31 schrieb Matthew Wilcox:  
> > > On Fri, Oct 30, 2020 at 08:37:48AM +0100, Mauro Carvalho Chehab wrote:  
> > > > Just changing the kernel-doc markup at kernel/futex.c:
> > > > 
> > > > 	/**
> > > > 	 * futex_setup_timer - set up the sleeping hrtimer.
> > > > 	 * @time:	ptr to the given timeout value
> > > > 	 * @timeout:	the hrtimer_sleeper structure to be set up
> > > > 	 * @flags:	futex flags
> > > > 	 * @range_ns:	optional range in ns
> > > > 	 *
> > > > 	 * Return: Initialized hrtimer_sleeper structure or NULL if no timeout
> > > > 	 *	   value given
> > > > 	 */
> > > > 
> > > > To:
> > > > 
> > > > ...
> > > > 	 * Return:
> > > > 	 *
> > > > 	 * Initialized hrtimer_sleeper structure or NULL if no timeout
> > > > 	 * value given
> > > > 	 */
> > > > 
> > > > Should fix it.  
> > > 
> > > Or just remove the indent.
> > > 
> > >   * Return: Initialized hrtimer_sleeper structure or NULL if no timeout
> > >   * value given.  
> > 
> > To add my 2 cent:
> > 
> > The return value should be described in a dedicated section
> > named "Return:", like shown im Mauro's example (compare [1]).
> > 
> > For on-liners I think it is OK to use the short form (compare [2]).
> > 
> > [1] https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html#return-values
> > [2] https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html#function-documentation  

Yeah, I would use myself something like:

	Return: foo

only for single-line returns, using:

	Return:

	foo
	bar

for multi-line ones.

-

Anyway, I tried the enclosed patch. With that, it should now recognize 
kernel-doc markups with:

 	 * Return: Initialized hrtimer_sleeper structure or NULL if no timeout
 	 *	   value given

And:

	 * Returns: 0 on success, -ENOSPC if no suitable hole is found, -EINTR if
	 * asked to wait for eviction and interrupted.
	 */
	(this example came from drivers/gpu/drm/i915/i915_gem_gtt.c)

I only did a fast check here, in order to verify if it won't be
producing additional warnings. I didn't check the html output.
Just the resulting ReST from kernel-doc and the "make htmldocs" warnings.

PS.: This handles only "Note(s)" and "Return(s)" sections.
     Description and @var: are already handled using a different
     logic elsewhere.

     This could likely be generalized, but more work (and tests)
     are required.

Thanks,
Mauro

[PATCH] scripts: kernel-doc: better handle spaces after section markups

Better handle things like:

	* Return: foo
	*         description

Suggested-by: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

diff --git a/scripts/kernel-doc b/scripts/kernel-doc
index f699cf05d409..a91a2420cccf 100755
--- a/scripts/kernel-doc
+++ b/scripts/kernel-doc
@@ -389,7 +389,7 @@ my $doc_com_body = '\s*\* ?';
 my $doc_decl = $doc_com . '(\w+)';
 # @params and a strictly limited set of supported section names
 my $doc_sect = $doc_com .
-    '\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:(.*)';
+    '\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)(\s*:)(.*)';
 my $doc_content = $doc_com_body . '(.*)';
 my $doc_block = $doc_com . 'DOC:\s*(.*)?';
 my $doc_inline_start = '^\s*/\*\*\s*$';
@@ -865,8 +865,21 @@ sub output_highlight_rst {
     my $in_literal = 0;
     my $litprefix;
     my $block = "";
+    my $spaces = "";
+    my $first = 1;
 
     foreach $line (split "\n",$input) {
+        if ($first) {
+		$spaces = $1 if ($line =~ (m/^(\s+)/));
+		$first = 0;
+        }
+
+        if ($spaces ne "") {
+		if (!($line =~ s/^$spaces//)) {
+		    $spaces = "";
+		}
+        }
+
 	#
 	# If we're in a literal block, see if we should drop out
 	# of it.  Otherwise pass the line straight through unmunged.
@@ -2135,8 +2148,9 @@ sub process_body($$) {
     }
 
     if (/$doc_sect/i) { # case insensitive for supported section names
+	my $spaces = "$1$2";
 	$newsection = $1;
-	$newcontents = $2;
+	$newcontents = $3;
 
 	# map the supported section names to the canonical names
 	if ($newsection =~ m/^description$/i) {
@@ -2161,11 +2175,20 @@ sub process_body($$) {
 
 	$in_doc_sect = 1;
 	$state = STATE_BODY;
-	$contents = $newcontents;
 	$new_start_line = $.;
-	while (substr($contents, 0, 1) eq " ") {
-	    $contents = substr($contents, 1);
+
+	if ($newsection =~ m/(return|note)/i) {
+	    $spaces =~ s/\S/ /g;
+	    $newcontents = $spaces . $newcontents;
+	    $newcontents =~ s/^\s+$//;
+	    $contents = $newcontents;
+	} else {
+	    $contents = $newcontents;
+	    while (substr($newcontents, 0, 1) eq " ") {
+		$newcontents = substr($newcontents, 1);
+	    }
 	}
+
 	if ($contents ne "") {
 	    $contents .= "\n";
 	}



  reply	other threads:[~2020-10-30 14:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-30  3:17 excess bolding in html Randy Dunlap
2020-10-30  7:37 ` Mauro Carvalho Chehab
2020-10-30 11:31   ` Matthew Wilcox
2020-10-30 12:28     ` Markus Heiser
2020-10-30 12:53       ` Matthew Wilcox
2020-10-30 14:00         ` Mauro Carvalho Chehab [this message]
2020-10-30 14:19           ` [PATCH RFC] scripts: kernel-doc: better handle spaces after section markups Mauro Carvalho Chehab
2020-10-30 17:30           ` excess bolding in html Randy Dunlap

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201030150019.1cc6db7d@coco.lan \
    --to=mchehab@kernel.org \
    --cc=corbet@lwn.net \
    --cc=linux-doc@vger.kernel.org \
    --cc=markus.heiser@darmarit.de \
    --cc=rdunlap@infradead.org \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).