Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 5C676431FBF for ; Wed, 7 May 2014 14:24:50 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id llgTAAKsAXcL for ; Wed, 7 May 2014 14:24:44 -0700 (PDT) Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) by olra.theworths.org (Postfix) with ESMTP id 92F60431FAE for ; Wed, 7 May 2014 14:24:44 -0700 (PDT) Received: by guru.guru-group.fi (Postfix, from userid 501) id 2DD0D1000F2; Thu, 8 May 2014 00:24:40 +0300 (EEST) From: Tomi Ollila To: notmuch@notmuchmail.org Subject: [PATCH] devel: make man-to-mdwn.pl to work with generated manual pages Date: Thu, 8 May 2014 00:24:39 +0300 Message-Id: <1399497879-27392-1-git-send-email-tomi.ollila@iki.fi> X-Mailer: git-send-email 1.8.0 Cc: tomi.ollila@iki.fi X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 May 2014 21:24:50 -0000 The new manual pages converted from rst using sphinx or rst2man has somewhat different syntax. man-to-mdwn.pl is now adjusted to produce even better output from this syntax (a bug ot two was fixed along the adjustents done). This tool still produces better results than just using the html pages generated using sphinx / rst2html. For example those tools don't create inter-page hyperlinks -- and the preformatted pages written by man-to-mdwn.pl just works well with manual page content. --- With the notmuch-wiki commit b2e421fc7 (Thu May 8 00:12:05 2014 +0300) the manpages* content is generated by this tool on scientific linux 6.2 machine and no manual post-editing was done. devel/man-to-mdwn.pl | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/devel/man-to-mdwn.pl b/devel/man-to-mdwn.pl index 4b59bd663698..64e6202ae970 100755 --- a/devel/man-to-mdwn.pl +++ b/devel/man-to-mdwn.pl @@ -6,18 +6,18 @@ # This program is used to generate mdwn-formatted notmuch manual pages # for notmuch wiki. Example run: # -# $ ./devel/man-to-mdwn.pl man ../notmuch-wiki +# $ ./devel/man-to-mdwn.pl doc/_build/man ../notmuch-wiki # # In case taken into more generic use, modify these comments and examples. -use 5.8.1; +use 5.10.1; use strict; use warnings; unless (@ARGV == 2) { warn "\n$0 \n\n"; # Remove/edit this comment if this script is taken into generic use. - warn "Example: ./devel/man-to-mdwn.pl man ../notmuch-wiki\n\n"; + warn "Example: ./devel/man-to-mdwn.pl doc/_build/man ../notmuch-wiki\n\n"; exit 1; } @@ -48,11 +48,6 @@ while (

) } close P; -#undef $ENV{'GROFF_NO_SGR'}; -#delete $ENV{'GROFF_NO_SGR'}; -$ENV{'GROFF_NO_SGR'} = '1'; -$ENV{'TERM'} = 'vt100'; # does this matter ? - my %htmlqh = qw/& & < < > > ' ' " "/; # do html quotation to $_[0] (which is an alias to the given arg) sub htmlquote($) @@ -70,8 +65,10 @@ while (my ($k, $v) = each %fhash) #next if -l $v; # skip symlinks here. -- not... references there may be. my @lines; - #open I, '-|', qw/groff -man -T utf8/, $v; - open I, '-|', qw/groff -man -T latin1/, $v; # this and GROFF_NO_SGR='1' + open I, '-|', qw/env -i/, "PATH=$ENV{PATH}", + qw/GROFF_NO_SGR=1 TERM=vt100 LANG=en_US.utf8 LC_ALL=en_US.utf8/, + qw/man/, $v; + #qw/man -t -E utf8 -T utf8/, $v; # <- needs newer man... my ($emptyline, $pre, $hl) = (0, 0, 'h1'); while () { @@ -79,13 +76,15 @@ while (my ($k, $v) = each %fhash) $emptyline = 1; next; } - s/(?<=\S)\s{8,}.*//; # $hl = 'h1' if s/(?<=\S)\s{8,}.*//; - htmlquote $_; + # keep only leftmost in lines like 'NOTMUCH(1) notmuch NOTMUCH(1)' + s/\S\K\s{8,}\S.+\s{8,}\S.*//; # $hl = 'h1' if s/(?<=\S)\s{8,}.*//; s/[_&]\010&/&/g; - s/((?:_\010[^_])+)/$1<\/u>/g; + s/((?:_\010[^_])+)/\001u\002$1\001\/u\002/g; s/_\010(.)/$1/g; - s/((?:.\010.)+)/$1<\/b>/g; + s/((?:.\010.)+)/\001b\002$1\001\/b\002/g; s/.\010(.)/$1/g; + htmlquote $_; + s/\001//g; if (/^\S/) { $pre = 0, push @lines, "\n" if $pre; @@ -116,7 +115,7 @@ while (my ($k, $v) = each %fhash) my $pe = ''; foreach (@lines) { if ($pe) { - if (s/^(\s+)([^<]+)<\/b>\((\d+)\)//) { + if (s/^(\s+)([^<]+)\((\d+)\)<\/b>//) { my $link = maymakelink "$pe-$2-$3"; $link = maymakelink "$pe$2-$3" unless $link; if ($link) { @@ -132,7 +131,7 @@ while (my ($k, $v) = each %fhash) } $pe = ''; } - s/([^<]+)<\/b>\((\d+)\)/mayconvert($1, $2)/ge; + s/([^<]+)\((\d+)\)<\/b>/mayconvert($1, $2)/ge; $pe = $1 if s/([^<]+)-<\/b>\s*$//; print $_; } @@ -169,7 +168,7 @@ foreach (sort srt values %fhash) open I, '<', $in or die $!; my $s; while () { - if (/^\s*[.]TH\s+\S+\s+(\S+)/) { + if (/^\s*[.]TH\s+\S+\s+"?(\S+?)"?\s/) { $s = $1; last; } -- 1.8.0