https://github.com/colinodell' introduced a PHP library called Indentation, that can be utilized to detect and manipulate the indentation of files and strings. Detecting the indentation of a string or file use ColinODell\Indentation\Indentation; $indentation = Indentation::detect(file_get_contents('composer.json')); assert($indentation->getAmount() === 4); assert($indentation->getType() === Indentation::TYPE_SPACE); assert((string)$indentation === ' '); Changing the indentation of a string or file use ColinODell\Indentation\Indentation; $composerJson = file_get_contents('composer.json'); $composerJson = Indentation::change($composerJson, new Indentation(1, Indentation::TYPE_TAB)); file_put_contents('composer.json', $composerJson); Adding leading indentation to all lines

use ColinODell\Indentation\Indentation; $codeExample = file_get_contents('file.php'); $indented = Indentation::indent($codeExample, new Indentation(4, Indentation::TYPE_SPACE)); Now you can embed the https://spec.commonmark.org/0.30/#indented-code-blocks into a Markdown document!

Imagine you have a file where every line is indented by at least 4 spaces: /** * Just a silly example */ class Cat extends Animal { //... }

Note how the leading 4 spaces are removed but all other indentation (like in the docblock and method body) is preserved.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners