phppkg/cli-markdown
CLI-Markdown renders Markdown with ANSI colors in your terminal. Built on cebe/markdown and toolkit/cli-utils, it supports automatic color rendering and customizable CLI color tags. Load Markdown text, call render(), and echo the result for a styled console output.
cebe/markdown (proven parser) and toolkit/cli-utils (color rendering), reducing technical debt. Aligns with Laravel’s preference for composable, dependency-injected components.echo or Symfony/Console styling with dynamic Markdown rendering.RuntimeException with code blocks).php artisan make:model --help).render() method with no side effects; easy to mock for testing.cebe/markdown (v1.2+) and toolkit/cli-utils (~2.0) are stable and widely adopted.ext-intl or ext-gd).toolkit/cli-utils's cross-platform detection or add a --no-color flag.> Note: Colors disabled. Enable ANSI support for full rendering.).cebe/markdown may not support Laravel-specific syntax (e.g., Blade directives, custom Artisan tags).php artisan --help output). Optimize with caching for static content.toolkit/cli-utils adds ~10KB; negligible for CLI tools but track for web-facing Laravel apps.Symfony/Console styling entirely or augment it (e.g., for help text only)?config/cli.php) or allow per-command overrides?'cli-markdown' => [
'colors' => [
'heading' => '#2d3748',
'code' => '#4a5568',
],
'enable_ansi' => env('TERM') !== 'dumb', // Disable on non-ANSI terminals
],
> Enable colors with: $ export TERM=xterm-256color)?artisan --help)?symfony/console test utilities)?php artisan --help)?laravel/cli-markdown wrapper package be created for easier dependency management?echo or Symfony/Console helpers with Markdown rendering.// Before
$this->output->writeln('<info>Usage:</info> command:desc');
// After
$markdown = "**Usage:**\n```bash\ncommand:desc\n```";
$this->output->writeln((new CliMarkdown())->render($markdown));
report(new RuntimeException("Failed to migrate: **table1** already exists"));
App\Exceptions\Handler:
public function render($request, Throwable $exception) {
if ($exception instanceof RuntimeException) {
return response()->json([
'error' => (new CliMarkdown())->render($exception->getMessage()),
]);
}
// ...
}
// In Tinker's PSR-3 logger or custom commands
$renderer = new CliMarkdown();
echo $renderer->render("## Variable: `$var`\n```php\n" . print_r($var, true) . "\n```");
php artisan migrate:status with formatted diffs).php artisan about or a custom command).php artisan --help and validate terminal output across platforms (Linux/macOS/Windows).php artisan --help output).MarkdownRenderer facade/service:
// app/Providers/AppServiceProvider.php
public function register() {
$this->app->singleton(CliMarkdown::class, function ($app) {
$renderer = new \PhpPkg\CliMarkdown\CliMarkdown();
if (!$app['config']->get('cli-markdown.enable_ansi')) {
$renderer->disableColors();
}
return $renderer;
});
}
Illuminate\Console\Command to support Markdown rendering via a trait:
use Illuminate\Console\Command;
use PhpPkg\CliMarkdown\CliMarkdown;
trait RendersMarkdown {
protected function markdown(string $content): string {
return app(CliMarkdown::class)->render($content);
}
}
class MyCommand extends Command {
use RendersMarkdown;
// ...
}
laravel/cli-markdown package (fork or wrapper) for dependency management:
composer require laravel/cli-markdown
php artisan markdown:demo command to showcase capabilities.FormatterHelper; no conflicts. Use for Markdown-specific needs (e.g., help text).toolkit/cli-utils's cross-platform ANSI handling or provide a Windows-specific fallback:
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$renderer->disableColors();
}
symfony/console version (v5.4+).composer.json:
"require": {
"phppkg/cli-markdown": "^2.0",
"toolkit/cli-utils": "^2.0" // If not already included
}
composer update.CliMarkdown service (as shown above).config/cli-markdown.php) for customization:
return [
'enable_ansi' => env('TERM') !== 'dumb',
'colors' => [
'heading' => '#
How can I help you explore Laravel packages today?