Skip to content

Commit

Permalink
refactor: merge markdown environment configuration instead of replace (
Browse files Browse the repository at this point in the history
  • Loading branch information
alfonsobries authored Oct 20, 2022
1 parent 990cf11 commit 810b26e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 29 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,4 @@
"spatie/laravel-permission": "Needed for nova permissions & roles",
"vyuldashev/nova-permission": "Needed for nova permissions & roles"
}
}
}
30 changes: 4 additions & 26 deletions config/markdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use League\CommonMark\Extension\SmartPunct\SmartPunctExtension;
use League\CommonMark\Extension\Strikethrough\StrikethroughExtension;
use League\CommonMark\Extension\TaskList\TaskListExtension;
use League\CommonMark\Normalizer\SlugNormalizer;

/*
* This file is part of Laravel Markdown.
Expand Down Expand Up @@ -206,32 +205,11 @@

/*
|--------------------------------------------------------------------------
| Default Config
| Environment Configuration
|--------------------------------------------------------------------------
|
| This option specifies the maximum permitted block nesting level.
|
| The options below are going to be deep merged with the default options
| defined on the `src/Providers/CommonMarkServiceProvider.php` file.
*/

'environment' => [
'external_link' => [
'internal_hosts' => config('app.url'),
'open_in_new_window' => true,
'html_class' => 'external-link',
'nofollow' => '',
'noopener' => 'external',
'noreferrer' => 'external',
'infix' => ' ',
],
'heading_permalink' => [
'html_class' => 'heading-permalink',
'id_prefix' => 'user-content',
'insert' => 'before',
'title' => 'Permalink',
'symbol' => '#',
],
'slug_normalizer' => [
'instance' => new SlugNormalizer(),
],
],
'environment' => [],
];
17 changes: 15 additions & 2 deletions src/Providers/CommonMarkServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,20 @@ private function registerCommonMarkEnvironment(): void
$environment->addExtension(resolve($extension));
}

$environment->mergeConfig(config('markdown.environment', [
$environment->mergeConfig($this->getConfiguration());
}

private function getConfiguration(): array
{
return array_replace_recursive(
$this->getDefaultConfiguration(),
Config::get('markdown.environment', [])
);
}

private function getDefaultConfiguration(): array
{
return [
'external_link' => [
'internal_hosts' => config('app.url'),
'open_in_new_window' => true,
Expand All @@ -232,6 +245,6 @@ private function registerCommonMarkEnvironment(): void
'slug_normalizer' => [
'instance' => new SlugNormalizer(),
],
]));
];
}
}

0 comments on commit 810b26e

Please sign in to comment.