Skip to content

Commit 65d6fc2

Browse files
committedApr 17, 2011
add dump_sd_help.pl (from old syncwith.us repo)
1 parent 724f75e commit 65d6fc2

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
 

‎tools/dump_sd_help.pl

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/usr/bin/perl
2+
# Process sd help output to put on the website (markdown)
3+
use strict;
4+
use warnings;
5+
6+
open GETHELP, 'sd help |' ;
7+
my @cmds;
8+
9+
# grab what helps exist from the help index
10+
while (<GETHELP>) {
11+
next if !m/sd help /;
12+
(undef, undef, my $cmd, undef, my $desc) = split ' ', $_, 5;
13+
# push @cmds, [$cmd, $desc];
14+
push @cmds, $cmd;
15+
}
16+
17+
close GETHELP;
18+
19+
# @cmds = ('environment'); # debug
20+
21+
print qq{[[!meta title="Using SD"]]\n};
22+
23+
for (@cmds) {
24+
open my $cmd, "sd help $_ |";
25+
my $text = slurp($cmd);
26+
27+
# now we can do the real processing
28+
print process_help($text);
29+
}
30+
31+
sub process_help {
32+
my ( $text ) = shift;
33+
34+
# escape markdown metacharacters
35+
$text =~ s/_/\\_/g;
36+
37+
# linkify http links, adapted from MRE 74
38+
$text =~ s{
39+
\b
40+
# Capture the URL to $1
41+
(
42+
# hostname
43+
http:// (?!example) [-a-z0-9]+(\.[-a-z0-9]+)*\.(com|org|us) \b
44+
(
45+
/ [-a-z0-9_:\@&?=?=+,.!/~*`%\$]* # optional path
46+
)?
47+
)
48+
}{[$1]($1)}gix;
49+
50+
# strip off extraneous leading newlines and convert the header into a
51+
# headline
52+
$text =~ s/^\n+sd \d\.\d\d - (.*)\n-+\n+/\n$1\n==========\n\n/;
53+
54+
# strip off any lines that read 'see 'sd help $cmd'' which isn't
55+
# really appropriate for this as all the helpfiles are being displayed
56+
# in one place
57+
#$text =~ s/^.*(?=(?:For more informatio on [\w ]+)? see 'sd help).*$//mgs;
58+
59+
# put codeblock markers around code blocks
60+
$text =~ s/((?:^ \S.*\n)+)/> $1/mg;
61+
62+
# put code annotation markup around code annotations (lines indented
63+
# by 6 spaces in the raw help (this markup doesn't exist yet in the CSS)
64+
$text =~ s/((?:^ \S.*\n)+)/<p class="code-annotation">$1<\/p>\n/mg;
65+
66+
return $text;
67+
} # process_help_file
68+
69+
sub slurp {
70+
my $fh = shift;
71+
local( $/ ) ;
72+
my $text = <$fh>;
73+
74+
return $text;
75+
}

0 commit comments

Comments
 (0)
Please sign in to comment.