From patchwork Fri Aug 21 19:39:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Cesar Lemes de Paula X-Patchwork-Id: 7053651 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 188FAC05AC for ; Fri, 21 Aug 2015 19:39:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F07942053C for ; Fri, 21 Aug 2015 19:39:33 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id AE24B2052A for ; Fri, 21 Aug 2015 19:39:32 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8564E6E416; Fri, 21 Aug 2015 12:39:30 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [93.93.135.160]) by gabe.freedesktop.org (Postfix) with ESMTPS id CC8156E3FF; Fri, 21 Aug 2015 12:39:28 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: danilo) with ESMTPSA id 55E56608F3B From: Danilo Cesar Lemes de Paula To: Date: Fri, 21 Aug 2015 16:39:02 -0300 Message-Id: <1440185942-31030-1-git-send-email-danilo.cesar@collabora.co.uk> X-Mailer: git-send-email 2.4.3 Cc: Michal Marek , Herbert Xu , Danilo Cesar Lemes de Paula , Jonathan Corbet , Stephan Mueller , Daniel Vetter , intel-gfx , Randy Dunlap , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel , Graham Whaley , Laurent Pinchart Subject: [Intel-gfx] [PATCH] scripts/kernel-doc: Improve Markdown results X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Using pandoc as the Markdown engine cause some minor side effects as pandoc includes main tags for almost everything. Original Markdown support approach removes those main tags, but it caused some inconsistencies when that tag is not the main one, like: .. ... As kernel-doc was already including a tag, it causes the presence of double tags (), which is not supported by DocBook spec. Html target gets away with it, so it causes no harm, although other targets might not be so lucky (pdf as example). We're now delegating the inclusion of the main tag to pandoc only, as it knows when it's necessary or not. That behavior causes a corner case, the only situation where we're certainly that is not needed, which is the content. For those cases, we're using a $output_markdown_nopara = 1 control var. Signed-off-by: Danilo Cesar Lemes de Paula Cc: Randy Dunlap Cc: Daniel Vetter Cc: Laurent Pinchart Cc: Jonathan Corbet Cc: Herbert Xu Cc: Stephan Mueller Cc: Michal Marek Cc: linux-kernel@vger.kernel.org Cc: linux-doc@vger.kernel.org Cc: intel-gfx Cc: dri-devel Cc: Graham Whaley Tested-by: Graham Whaley --- Thanks to Graham Whaley who helped me to debug this. scripts/kernel-doc | 48 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/scripts/kernel-doc b/scripts/kernel-doc index 3850c1e..12a106c 100755 --- a/scripts/kernel-doc +++ b/scripts/kernel-doc @@ -288,6 +288,7 @@ my $use_markdown = 0; my $verbose = 0; my $output_mode = "man"; my $output_preformatted = 0; +my $output_markdown_nopara = 0; my $no_doc_sections = 0; my @highlights = @highlights_man; my $blankline = $blankline_man; @@ -529,8 +530,11 @@ sub markdown_to_docbook { close(CHLD_OUT); close(CHLD_ERR); - # pandoc insists in adding Main , we should remove them. - $content =~ s:\A\s*\s*\n(.*)\n\Z$:$1:egsm; + if ($output_markdown_nopara) { + # pandoc insists in adding Main , sometimes we + # want to remove them. + $content =~ s:\A\s*\s*\n(.*)\n\Z$:$1:egsm; + } return $content; } @@ -605,7 +609,7 @@ sub output_highlight { $line =~ s/^\s*//; } if ($line eq ""){ - if (! $output_preformatted) { + if (! $output_preformatted && ! $use_markdown) { print $lineprefix, local_unescape($blankline); } } else { @@ -1026,7 +1030,7 @@ sub output_section_xml(%) { # programlisting is already included by pandoc print "\n" unless $use_markdown; $output_preformatted = 1; - } else { + } elsif (! $use_markdown) { print "\n"; } output_highlight($args{'sections'}{$section}); @@ -1034,7 +1038,7 @@ sub output_section_xml(%) { if ($section =~ m/EXAMPLE/i) { print "\n" unless $use_markdown; print "\n"; - } else { + } elsif (! $use_markdown) { print "\n"; } print "\n"; @@ -1066,7 +1070,9 @@ sub output_function_xml(%) { print " " . $args{'function'} . "\n"; print " \n"; print " "; + $output_markdown_nopara = 1; output_highlight ($args{'purpose'}); + $output_markdown_nopara = 0; print " \n"; print "\n"; @@ -1104,10 +1110,12 @@ sub output_function_xml(%) { $parameter_name =~ s/\[.*//; print " \n $parameter\n"; - print " \n \n"; + print " \n"; + print " \n" unless $use_markdown; $lineprefix=" "; output_highlight($args{'parameterdescs'}{$parameter_name}); - print " \n \n \n"; + print " \n" unless $use_markdown; + print " \n \n"; } print " \n"; } else { @@ -1143,7 +1151,9 @@ sub output_struct_xml(%) { print " " . $args{'type'} . " " . $args{'struct'} . "\n"; print " \n"; print " "; + $output_markdown_nopara = 1; output_highlight ($args{'purpose'}); + $output_markdown_nopara = 0; print " \n"; print "\n"; @@ -1196,9 +1206,11 @@ sub output_struct_xml(%) { ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; print " "; print " $parameter\n"; - print " \n"; + print " \n"; + print " \n" unless $use_markdown; output_highlight($args{'parameterdescs'}{$parameter_name}); - print " \n"; + print " \n" unless $use_markdown; + print " \n"; print " \n"; } print " \n"; @@ -1237,7 +1249,9 @@ sub output_enum_xml(%) { print " enum " . $args{'enum'} . "\n"; print " \n"; print " "; + $output_markdown_nopara = 1; output_highlight ($args{'purpose'}); + $output_markdown_nopara = 0; print " \n"; print "\n"; @@ -1267,9 +1281,11 @@ sub output_enum_xml(%) { print " "; print " $parameter\n"; - print " \n"; + print " \n"; + print " \n" unless $use_markdown; output_highlight($args{'parameterdescs'}{$parameter_name}); - print " \n"; + print " \n" unless $use_markdown; + print " \n"; print " \n"; } print " \n"; @@ -1335,14 +1351,14 @@ sub output_blockhead_xml(%) { if ($section =~ m/EXAMPLE/i) { print "\n"; $output_preformatted = 1; - } else { + } elsif (! $use_markdown) { print "\n"; } output_highlight($args{'sections'}{$section}); $output_preformatted = 0; if ($section =~ m/EXAMPLE/i) { print "\n"; - } else { + } elsif (! $use_markdown) { print ""; } if (!$args{'content-only'}) { @@ -2684,7 +2700,11 @@ sub process_file($) { { if ( $1 eq "" ) { - $contents .= $blankline; + if ($use_markdown) { + $contents .= "\n"; + } else { + $contents .= $blankline; + } } else {