generated from hashbangcode/marp-talk-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtable_of_contents.php
52 lines (38 loc) · 1.08 KB
/
table_of_contents.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
<?php
$slidesFile = './src/slides.md';
$fileContents = file_get_contents($slidesFile);
$slides = explode("---" . PHP_EOL, $fileContents);
$tocArray = [];
$toc = '';
$toc .= '<!-- _footer: "" -->' . PHP_EOL;
$toc .= PHP_EOL . '## Contents' . PHP_EOL . PHP_EOL;
$toc .= "<style>
.container {
display: flex;
font-size: 0.8rem;
}
.col {
flex: 1;
}
</style>";
$toc .= PHP_EOL . '<div class="container">' . PHP_EOL . PHP_EOL;
$bulletCount = 0;
foreach ($slides as $id => $slide) {
if (preg_match('/^#{1}\s(.*)/m', $slide, $matches)) {
if ($bulletCount == 0) {
$toc .= '<div class="col">' . PHP_EOL;
}
$toc .= PHP_EOL . '- [' . $matches[1] . '](#' . ($id-2) . ')';
$bulletCount++;
if ($bulletCount == 10) {
$bulletCount = 0;
$toc .= PHP_EOL . PHP_EOL . '</div>' . PHP_EOL . PHP_EOL;
}
}
}
$toc .= PHP_EOL . PHP_EOL . '</div>';
$toc .= PHP_EOL . '</div>' . PHP_EOL . PHP_EOL;
$slides[4] = $toc;
$slides = trim(implode("---\n", $slides));
file_put_contents($slidesFile, $slides);
echo 'done.';