When we maintain a package docs or generate documentation in Markdown, we write a code snippet from time to time. The clearest way to show what you exactly mean is a diff. That's why diff is used in GitHub commit suggestions.
"Diff is worth 100 code-review words."
But creating automated diff in Markdown is a pickle. We picked the pickle and turned it into a package - symplify/markdown-diff package.
The package does exactly what it says and is mostly used in symplify/rule-doc-generator. I'd say this is the smallest package on Symplify.
composer require symplify/markdown-diff
config/bundles.php
use Symplify\MarkdownDiff\Bundle\MarkdownDiffBundle;
return [
MarkdownDiffBundle::class => [
'all' => true,
],
];
namespace App;
use Symplify\MarkdownDiff\Differ\MarkdownDiffer;
final class SomeClass
{
/**
* @var MarkdownDiffer
*/
private $markdownDiffer;
public function __construct(MarkdownDiffer $markdownDiffer)
{
$this->markdownDiffer = $markdownDiffer;
}
public function run(): void
{
$markdownDiff = $this->markdownDiffer->diff('oldContent', 'newContent');
// ...
file_put_contents(getcwd() . '/docs/diff.md', $markdownDiff);
}
}
↓
-'oldContent'
+'newContent'
Pretty simple, right?
Compared to sebastian/diff it builds on, this package does an extra cleaning job:
---/+++ @@
spamThat's all for today.
Happy coding!
Do you learn from my contents or use open-souce packages like Rector every day?
Consider supporting it on GitHub Sponsors.
I'd really appreciate it!