Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist_code_examples.php
More file actions
Latest commit
35 lines (27 loc) · 1.04 KB
/
Copy pathlist_code_examples.php
File metadata and controls
35 lines (27 loc) · 1.04 KB
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
<?php
/**
* @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause
* @copyright Copyright (c) 2019-2020 Laminas Project (https://getlaminas.org)
*/
$docPath = isset($argv[1]) ? $argv[1] : 'doc';
$docPath = sprintf('%s/%s', getcwd(), $docPath);
$docPath = realpath($docPath);
$rdi = newRecursiveDirectoryIterator($docPath . '/book');
$rii = newRecursiveIteratorIterator($rdi, RecursiveIteratorIterator::SELF_FIRST);
$files = newRegexIterator($rii, '/\.md/', RecursiveRegexIterator::GET_MATCH);
$process = staticfunction () use ($files) {
$fileInfo = $files->getInnerIterator()->current();
if (! $fileInfo->isFile()) {
returntrue;
}
if ($fileInfo->getBasename('.md') === $fileInfo->getBasename()) {
returntrue;
}
$file = $fileInfo->getRealPath();
$md = file_get_contents($file);
$md = preg_replace('#^[-*]$#m', '\\0 ', $md);
$md = preg_replace('#^([-*] +)```#m', '\\1' . PHP_EOL . ' ```', $md);
file_put_contents($file, $md);
returntrue;
};
iterator_apply($files, $process);