forked from slic3r/Slic3r-Manual
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make-html.pl
executable file
·146 lines (131 loc) · 4.57 KB
/
make-html.pl
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/perl
use strict;
use warnings;
use List::Util qw(first);
if (!-d "html") {
die "This script must be run from the Slic3r-Manual directory\n";
}
# read chapters
my @chapters = ();
{
open my $fh, "<", "Slic3r-Manual.tex";
while (<$fh>) {
if (m[\\chapter{\\emph{(.+?)}}]) {
push @chapters, { title => $1, include => [], sections => [] };
$chapters[-1]{title} =~ s/\\//g;
}
if (m[\\include{(.+?)}] && @chapters) {
push @{ $chapters[-1]{include} }, $1
unless $1 =~ /Colophon/;
}
}
close $fh;
}
# read sections
foreach my $chapter (@chapters) {
my $include;
$include = sub {
push @{ $chapter->{include} }, $_[0];
open my $fh, "<", "$_[0].tex";
while (<$fh>) {
if (m[\\section{(.+?)}]) {
push @{ $chapter->{sections} }, $1;
$chapter->{sections}[-1] =~ s/\\//g;
}
if (m[\\input{(.+?)}]) {
$include->($1);
}
}
close $fh;
};
$include->($_) for map $_, @{ $chapter->{include} };
}
my $toc = <<"EOF";
<div id="manual-toc">
* [Introduction](Intro.html)
* [Overview](Intro.html)
* [Getting Support](Slic3rSupport.html)
* [Getting Slic3r](GettingSlic3r.html)
* [Downloading](GettingSlic3r.html#downloading)
* [Installing](GettingSlic3r.html#installing)
* [Building from source](GettingSlic3r.html#building-from-source)
* [First Print](FirstPrint.html)
* [Calibration](FirstPrint.html#calibration)
* [Configuration Wizard](FirstPrint.html#configuration-wizard)
* [The Important First Layer](FirstPrint.html#the-important-first-layer)
* [Working with Models](FirstPrint.html#working-with-models)
* [Printing](FirstPrint.html#printing)
* [Simple Mode](SimpleMode.html)
* [Print Settings](SimpleMode.html#print-settings)
* [Filament Settings](SimpleMode.html#filament-settings)
* [Printer Settings](SimpleMode.html#printer-settings)
* Expert Mode
* [Speed](Speed.html)
* [Infill Patterns and Density](InfillPatternsAndDensity.html)
* [Infill Optimization](InfillOptimization.html)
* [Fighting Ooze](FightingOoze.html)
* [Skirt](Skirt.html)
* [Cooling](Cooling.html)
* [Support Material](SupportMaterial.html)
* [Multiple Extruders](MultipleExtruders.html)
* [Extrusion Width](ExtrusionWidth.html)
* [Variable Layer Height](VariableLayerHeight.html)
* [Configuration Organization](ConfigurationOrganization.html)
* [Exporting and Importing Configuration](ConfigurationOrganization.html#exporting-and-importing-configuration)
* [Managing Profiles](ConfigurationOrganization.html#profiles)
* [Repairing Models](RepairingModels.html)
* Advanced Topics
* [Sequential Printing](SequentialPrinting.html)
* [SVG Output](SVGOutput.html)
* [Command Line Usage](CommandLineUsage.html)
* [Post-Processing Scripts](PostProcessingScripts.html)
* [Troubleshooting](Troubleshooting.html)
* [Z Wobble](Troubleshooting.html#z-wobble)
</div>
EOF
{
open my $fh, ">", "html/toc.md";
print $fh $toc;
close $fh;
system qw(pandoc html/toc.md -f markdown -t html -o html/toc.html);
}
# convert LaTeX to Markdown
foreach my $tex (glob "*.tex") {
my $md = $tex;
$md =~ s/\.tex/.md/;
system 'pandoc', $tex, qw(-f latex -t markdown -o), "html/$md";
}
# remove extra things ported from LaTeX
system qw(perl -pi -e s/\[(?:sec|sub|fig|par):.+?\]//), glob "html/*.md";
system qw(perl -pi -e s/\[H\]//), glob "html/*.md";
# add page titles
my %page_titles = ();
foreach my $line (split /\n/, $toc) {
if ($line =~ /\[(.+?)\]\(([^#]+?)\)/) {
my ($title, $file) = ($1, $2);
$file =~ s/#.*//;
$file =~ s/\.html$//;
$page_titles{$file} = $title;
}
}
# convert Markdown to HTML
system qw(cp html-inc/index.md html/);
foreach my $md (glob "html/*.md") {
next if $md eq 'html/toc.md';
my $html = $md;
$html =~ s/\.md/.html/;
my $title = 'Slic3r Manual';
if (my $page_title = first { "html/$_.md" eq $md } keys %page_titles) {
$title .= ": $page_titles{$page_title}";
}
system 'pandoc', $md, qw(-f markdown -t html -o), $html,
qw(--css style.css --title-prefix), $title,
qw( --include-before-body=html-inc/header.html
--include-before-body=html/toc.html
--include-before-body=html-inc/before-body.html
--include-after-body=html-inc/after-body.html);
}
# copy images and stylesheet
system qw(cp -rf), (glob "images-original/*"), "html/";
system qw(cp html-inc/style.css html/);
__END__