1 Return-Path: <too@guru-group.fi>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 10B99431FBC
\r
6 for <notmuch@notmuchmail.org>; Mon, 4 Aug 2014 10:40:03 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id aUjbAa9K+YFS for <notmuch@notmuchmail.org>;
\r
16 Mon, 4 Aug 2014 10:39:54 -0700 (PDT)
\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])
\r
18 by olra.theworths.org (Postfix) with ESMTP id 8145C431FAE
\r
19 for <notmuch@notmuchmail.org>; Mon, 4 Aug 2014 10:39:54 -0700 (PDT)
\r
20 Received: by guru.guru-group.fi (Postfix, from userid 501)
\r
21 id 85051100063; Mon, 4 Aug 2014 20:39:38 +0300 (EEST)
\r
22 From: Tomi Ollila <tomi.ollila@iki.fi>
\r
23 To: notmuch@notmuchmail.org
\r
24 Subject: [PATCH v2] devel: make man-to-mdwn.pl to work with generated manual
\r
26 Date: Mon, 4 Aug 2014 20:39:32 +0300
\r
27 Message-Id: <1407173972-28090-1-git-send-email-tomi.ollila@iki.fi>
\r
28 X-Mailer: git-send-email 2.0.0
\r
29 Cc: tomi.ollila@iki.fi
\r
30 X-BeenThere: notmuch@notmuchmail.org
\r
31 X-Mailman-Version: 2.1.13
\r
33 List-Id: "Use and development of the notmuch mail system."
\r
34 <notmuch.notmuchmail.org>
\r
35 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
36 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
37 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
38 List-Post: <mailto:notmuch@notmuchmail.org>
\r
39 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
40 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
41 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
42 X-List-Received-Date: Mon, 04 Aug 2014 17:40:03 -0000
\r
44 The new manual pages converted from rst using sphinx or rst2man
\r
45 has somewhat different syntax. man-to-mdwn.pl is now adjusted
\r
46 to produce even better output from this syntax. The changes also
\r
47 include using utf-8 locale (e.g. for tables and generated hypens)
\r
48 and and quite a few bugs fixes.
\r
49 This tool still produces better results than just using the
\r
50 html pages generated using sphinx / rst2html. For example those
\r
51 tools don't create inter-page hyperlinks -- and the preformatted
\r
52 pages written by man-to-mdwn.pl just works well with manual page
\r
56 This is version 2 of id:1399497879-27392-1-git-send-email-tomi.ollila@iki.fi
\r
58 The changes in notmuch-wiki commit 6562766 (Mon Aug 4 10:15:07 2014 +0300)
\r
59 were generated with this tool, now on Fedora 20 (should be comparable with
\r
60 Debian testing David used). Thanks to David for that -- quite a few things
\r
61 did now work on these systems compared to Scientific Linux 6.2.
\r
63 devel/man-to-mdwn.pl | 42 ++++++++++++++++++++++--------------------
\r
64 1 file changed, 22 insertions(+), 20 deletions(-)
\r
66 diff --git a/devel/man-to-mdwn.pl b/devel/man-to-mdwn.pl
\r
67 index 4b59bd663698..5024569e5d84 100755
\r
68 --- a/devel/man-to-mdwn.pl
\r
69 +++ b/devel/man-to-mdwn.pl
\r
71 # This program is used to generate mdwn-formatted notmuch manual pages
\r
72 # for notmuch wiki. Example run:
\r
74 -# $ ./devel/man-to-mdwn.pl man ../notmuch-wiki
\r
75 +# $ ./devel/man-to-mdwn.pl doc/_build/man ../notmuch-wiki
\r
77 # In case taken into more generic use, modify these comments and examples.
\r
84 unless (@ARGV == 2) {
\r
85 warn "\n$0 <source-directory> <destination-directory>\n\n";
\r
86 # Remove/edit this comment if this script is taken into generic use.
\r
87 - warn "Example: ./devel/man-to-mdwn.pl man ../notmuch-wiki\n\n";
\r
88 + warn "Example: ./devel/man-to-mdwn.pl doc/_build/man ../notmuch-wiki\n\n";
\r
92 @@ -48,11 +48,6 @@ while (<P>)
\r
96 -#undef $ENV{'GROFF_NO_SGR'};
\r
97 -#delete $ENV{'GROFF_NO_SGR'};
\r
98 -$ENV{'GROFF_NO_SGR'} = '1';
\r
99 -$ENV{'TERM'} = 'vt100'; # does this matter ?
\r
101 my %htmlqh = qw/& & < < > > ' ' " "/;
\r
102 # do html quotation to $_[0] (which is an alias to the given arg)
\r
104 @@ -70,8 +65,11 @@ while (my ($k, $v) = each %fhash)
\r
105 #next if -l $v; # skip symlinks here. -- not... references there may be.
\r
108 - #open I, '-|', qw/groff -man -T utf8/, $v;
\r
109 - open I, '-|', qw/groff -man -T latin1/, $v; # this and GROFF_NO_SGR='1'
\r
110 + open I, '-|', qw/env -i/, "PATH=$ENV{PATH}",
\r
111 + qw/TERM=vt100 LANG=en_US.utf8 LC_ALL=en_US.utf8/,
\r
112 + qw/GROFF_NO_SGR=1 MAN_KEEP_FORMATTING=1 MANWIDTH=80/,
\r
113 + qw/man/, $v or die "$!";
\r
114 + binmode I, ':utf8';
\r
116 my ($emptyline, $pre, $hl) = (0, 0, 'h1');
\r
118 @@ -79,13 +77,15 @@ while (my ($k, $v) = each %fhash)
\r
122 - s/(?<=\S)\s{8,}.*//; # $hl = 'h1' if s/(?<=\S)\s{8,}.*//;
\r
124 + # keep only leftmost in lines like 'NOTMUCH(1) notmuch NOTMUCH(1)'
\r
125 + s/\S\K\s{8,}\S.+\s{8,}\S.*//; # $hl = 'h1' if s/(?<=\S)\s{8,}.*//;
\r
127 - s/((?:_\010[^_])+)/<u>$1<\/u>/g;
\r
128 + s/((?:_\010[^_])+)/\001u\002$1\001\/u\002/g;
\r
130 - s/((?:.\010.)+)/<b>$1<\/b>/g;
\r
131 + s/((?:.\010.)+)/\001b\002$1\001\/b\002/g;
\r
134 + s/\001/</g; s/\002/>/g;
\r
137 $pre = 0, push @lines, "</pre>\n" if $pre;
\r
138 @@ -111,16 +111,18 @@ while (my ($k, $v) = each %fhash)
\r
139 $lines[0] =~ s/^\n//;
\r
140 $k = "$ARGV[1]/manpages/$k.mdwn";
\r
141 open O, '>', $k or die;
\r
142 + binmode O, ':utf8';
\r
143 print STDOUT 'Writing ', "'$k'\n";
\r
146 + my ($pe, $hyphen) = ('', '');
\r
150 - if (s/^(\s+)<b>([^<]+)<\/b>\((\d+)\)//) {
\r
151 + if (s/^(\s+)<b>([^<]+)\((\d+)\)<\/b>//) {
\r
152 my $link = maymakelink "$pe-$2-$3";
\r
153 $link = maymakelink "$pe$2-$3" unless $link;
\r
155 - print "<a href='$link'>$pe-</a>\n";
\r
156 + print "<a href='$link'>$pe$hyphen</a>\n";
\r
157 print "$1<a href='$link'>$2</a>($3)";
\r
160 @@ -132,8 +134,8 @@ while (my ($k, $v) = each %fhash)
\r
164 - s/<b>([^<]+)<\/b>\((\d+)\)/mayconvert($1, $2)/ge;
\r
165 - $pe = $1 if s/<b>([^<]+)-<\/b>\s*$//;
\r
166 + s/<b>([^<]+)\((\d+)\)<\/b>/mayconvert($1, $2)/ge;
\r
167 + ($pe, $hyphen) = ($1, $2) if s/<b>([^<]+)([-\x{2010}])<\/b>\s*$//;
\r
171 @@ -169,7 +171,7 @@ foreach (sort srt values %fhash)
\r
172 open I, '<', $in or die $!;
\r
175 - if (/^\s*[.]TH\s+\S+\s+(\S+)/) {
\r
176 + if (/^\s*[.]TH\s+\S+\s+"?(\S+?)"?\s/) {
\r