Last active
August 29, 2015 14:01
-
-
Save wouterj/fa6fb71d23d703cac7b9 to your computer and use it in GitHub Desktop.
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
<?php | |
require_once __DIR__.'/../vendor/autoload.php'; | |
use Gnugat\Redaktilo\Filesystem; | |
use Gnugat\Redaktilo\Editor; | |
use Gnugat\Redaktilo\File; | |
use Symfony\Component\Filesystem\Filesystem as SymfonyFilesystem; | |
$symfonyFilesystem = new SymfonyFilesystem(); | |
$filesystem = new Filesystem($symfonyFilesystem); | |
$editor = new Editor($filesystem); | |
$files = new \RegexIterator( | |
new \RecursiveIteratorIterator( | |
new \RecursiveDirectoryIterator(__DIR__.'/../') | |
), '/\.rst(?:\.inc)?$/', | |
\RegexIterator::MATCH | |
); | |
foreach ($files as $filename) { | |
$file = $editor->open($filename); | |
try { | |
remove_dollars($editor, $file); | |
} catch (\Exception $e) { | |
} | |
echo $filename, PHP_EOL; | |
$editor->save($file); | |
} | |
function remove_dollars(Editor $editor, File $file) { | |
$editor->jumpDownTo($file, '.. code-block:: bash'); | |
$lines = $file->readlines(); | |
$editor->moveDown($file); | |
while ((bool) preg_match('/^ /', $line = $lines[$file->getCurrentLineNumber()]) || '' === $line) { | |
if ('' !== $line) { | |
$editor->replaceWith($file, '/\$ /', ''); | |
} | |
$editor->moveDown($file); | |
} | |
remove_dollars($editor, $file); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment