-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b69e7ba
commit b5d4fb5
Showing
23 changed files
with
341 additions
and
442 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
use League\CommonMark\Environment\Environment; | ||
use League\CommonMark\Extension\CommonMark\Node\Block\FencedCode; | ||
use League\CommonMark\Node\Query; | ||
use League\CommonMark\Parser\MarkdownParser; | ||
use Wnx\CommonmarkMarkdownRenderer\MarkdownRendererExtension; | ||
use Wnx\CommonmarkMarkdownRenderer\Renderer\MarkdownRenderer; | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
|
||
|
||
$environment = new Environment([]); | ||
$environment->addExtension(new MarkdownRendererExtension()); | ||
|
||
$parser = new MarkdownParser($environment); | ||
$markdownRenderer = new MarkdownRenderer($environment); | ||
|
||
$targetDir = __DIR__ . '/../docs_php'; | ||
|
||
if (!file_exists($targetDir)) { | ||
exit(1); | ||
} | ||
|
||
$finder = new Symfony\Component\Finder\Finder(); | ||
$finder->files()->in(__DIR__ . '/../docs/pages')->name('*.md'); | ||
|
||
foreach ($finder as $file) { | ||
$fileName = pathinfo($file->getBasename(), PATHINFO_FILENAME); | ||
|
||
$content = file_get_contents($file->getPathname()); | ||
$document = $parser->parse($content); | ||
|
||
$result = (new Query()) | ||
->where(Query::type(FencedCode::class)) | ||
->findAll($document); | ||
|
||
/** | ||
* @var FencedCode $node | ||
*/ | ||
foreach ($result as $node) { | ||
if ($node->getInfo() !== 'php') { | ||
continue; | ||
} | ||
|
||
$targetPath = $targetDir . '/' . $fileName . '_' . $node->getStartLine() . '.php'; | ||
$code = file_get_contents($targetPath); | ||
|
||
$lines = explode("\n", $code); | ||
array_splice($lines, 0, 2); | ||
$code = implode("\n", $lines); | ||
|
||
$node->setLiteral(trim($code)); | ||
} | ||
|
||
file_put_contents($file->getPathname(), $markdownRenderer->renderDocument($document)); | ||
} | ||
|
||
if (file_exists($targetDir)) { | ||
exec('rm -rf ' . $targetDir); | ||
} |
Oops, something went wrong.