mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
Add HeaderSlug configurable
Adds HeaderSlug configurable, with the option for the slug function to be customised. Co-authored-by: netniV <netniv@hotmail.com>
This commit is contained in:
@@ -5,6 +5,7 @@ namespace Erusev\Parsedown\Components\Blocks;
|
||||
use Erusev\Parsedown\AST\Handler;
|
||||
use Erusev\Parsedown\AST\StateRenderable;
|
||||
use Erusev\Parsedown\Components\Block;
|
||||
use Erusev\Parsedown\Configurables\HeaderSlug;
|
||||
use Erusev\Parsedown\Configurables\StrictMode;
|
||||
use Erusev\Parsedown\Html\Renderables\Element;
|
||||
use Erusev\Parsedown\Parsedown;
|
||||
@@ -96,9 +97,16 @@ final class Header implements Block
|
||||
return new Handler(
|
||||
/** @return Element */
|
||||
function (State $State) {
|
||||
$HeaderSlug = $State->get(HeaderSlug::class);
|
||||
$attributes = (
|
||||
$HeaderSlug->isEnabled()
|
||||
? ['id' => $HeaderSlug->transform($this->text())]
|
||||
: []
|
||||
);
|
||||
|
||||
return new Element(
|
||||
'h' . \strval($this->level()),
|
||||
[],
|
||||
$attributes,
|
||||
$State->applyTo(Parsedown::line($this->text(), $State))
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user