-
Notifications
You must be signed in to change notification settings - Fork 24
/
compileman.php
130 lines (116 loc) · 5.19 KB
/
compileman.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
//Load all pages from the gitbook
$summary = file_get_contents("manList");
$summary = explode("\n", $summary);
$manPage = ".ce 1\n.SH -=-=-=-=-=-=-=-=-=- DOCS: LDPL DOCUMENTATION -=-=-=-=-=-=-=-=-=-\n";
foreach($summary as $line){
$line = trim($line);
if(strlen($line) > 0){
$manPage = $manPage . "\n\n" . file_get_contents($line);
}
else if(strlen($line) > 0 && trim(substr($line, 0, 2)) == "##"){
$manPage = $manPage . "\n\n" . ".ce 1\n.SH -=-=-=-=- DOCS: " . trim(strtoupper(substr($line, 2))) . " -=-=-=-=-";
}
}
//Replace all originally blank lines with <BLANK>
$manPage = explode("\n", $manPage);
foreach($manPage as &$line){
if(strlen(trim($line)) == 0){
$line = "<BLANK>";
}
}
$manPage = implode("\n", $manPage);
$manPage = str_replace("\\", "\\\\", $manPage);
$manPage = str_replace("\(", "(", $manPage);
$manPage = str_replace("\)", ")", $manPage);
$manPage = str_replace("**", "", $manPage);
$manPage = str_replace("_ ", " ", $manPage);
$manPage = str_replace(" _", " ", $manPage);
$manPage = preg_replace("/\!\[(.*?)\]\(.*?\)/m", "", $manPage);
$manPage = preg_replace("/\[(.*?)\]\(.*?\)/m", "$1", $manPage);
$manPage = preg_replace("/\:\:\:.*/m", "", $manPage);
$manPage = preg_replace("/\!\!\!\s*warning/m", "~ Warning ~", $manPage);
$manPage = preg_replace("/\!\!\!\s*hint/m", "~ Hint ~", $manPage);
$manPage = preg_replace("/\!\!\!\s*note/m", "~ Note ~", $manPage);
$manPage = preg_replace("/\!\!\!\s*tip/m", "~ Tip ~", $manPage);
$manPage = preg_replace("/\!\!\!\s*Warning/m", "~ Warning ~", $manPage);
$manPage = preg_replace("/\!\!\!\s*Hint/m", "~ Hint ~", $manPage);
$manPage = preg_replace("/\!\!\!\s*Note/m", "~ Note ~", $manPage);
$manPage = preg_replace("/\!\!\!\s*Tip/m", "~ Tip ~", $manPage);
/*$manPage = str_replace("\(", "(", $manPage);
$manPage = str_replace("\)", ")", $manPage);
$manPage = str_replace('{% hint style="info" %}', "-- Note:\n.br", $manPage);
$manPage = str_replace('{% hint style="warning" %}', "-- Warning:\n.br", $manPage);
$manPage = str_replace('{% endhint %}', ".br\n--", $manPage);
$manPage = str_replace('{% endcode-tabs-item %}', "", $manPage);
$manPage = str_replace('{% endcode-tabs %}', "", $manPage);
$manPage = str_replace('{% code-tabs %}', "", $manPage);
$manPage = str_replace('{% code-tabs-item title="', "File: ", $manPage);
$manPage = str_replace('" %}', "\n.br", $manPage);
$manPage = str_replace("\\", "\\\\", $manPage);
$manPage = str_replace("\[", "[", $manPage);
$manPage = str_replace("\]", "]", $manPage);
$manPage = str_replace("\#", "#", $manPage);
$manPage = str_replace(">", ">", $manPage);
$manPage = str_replace("<", "<", $manPage);*/
$manPage = explode("\n", $manPage);
$incode = false;
$lineNum = 1;
//Convert each page to groff
foreach($manPage as &$line){
$line = rtrim($line);
if(strlen($line) > 0 && substr($line, 0, 3) == "```"){
$incode = !$incode;
if($incode) $lineNum = 1;
$line = "";
}
else if($incode){
/*if($lineNum < 10)
$line = $lineNum . " | " . $line . "\n.br";
else
$line = $lineNum . "| " . $line . "\n.br";
$lineNum++;*/
$line = " " . $line . "\n.br";
}
else if(strlen($line) > 0 && substr(trim($line), 0, 2) == "* "){
//$line = ".br\n • " . trim(substr($line, 2));
$count = 1;
$line = str_replace("*", "•", $line, $count);
if(substr($line, 0, 4) != " "){
$line = " " . trim($line);
}
}
else if(strlen($line) > 0 && substr(trim($line), 0, 2) == "- "){
//$line = ".br\n • " . trim(substr($line, 2));
$count = 1;
$line = str_replace("-", "•", $line, $count);
if(substr($line, 0, 4) != " "){
$line = " " . trim($line);
}
}
else if(strlen($line) > 0 && substr($line, 0, 1) == "|"){
$line = ".br\n" . trim($line);
}
/*else if(strlen($line) > 0 && trim(substr($line, 0, 4)) == "####"){
$line = ".B " . trim(substr($line, 4));
}
if(strlen($line) > 0 && trim(substr($line, 0, 3)) == "###"){
$line = ".B " . trim(substr($line, 3));
}
else if(strlen($line) > 0 && trim(substr($line, 0, 2)) == "##"){
$line = ".B " . trim(substr($line, 2));
}
else if(strlen($line) > 0 && substr($line, 0, 1) == "#"){
$line = ".SH " . strtoupper(trim(substr($line, 1)));
}
else if($line == "!"){
$line = "";
}*/
}
$manPage = implode("\n", $manPage);
$manPage = str_replace('`', "'", $manPage);
$manPage = str_replace("\n\n", "\n", $manPage, $count);
$manPage = str_replace("\n<BLANK>\n", "\n\n", $manPage, $count);
$manPage = str_replace("<BLANK>", "", $manPage, $count);
echo file_get_contents("ldplman-intro") . "\n" . $manPage . "\n";
?>