1
0
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:
Aidan Woods
2020-05-04 22:02:20 +01:00
parent 74df602863
commit e332b4710a
7 changed files with 156 additions and 2 deletions

View File

@@ -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))
);
}

View File

@@ -6,6 +6,7 @@ use Erusev\Parsedown\AST\Handler;
use Erusev\Parsedown\AST\StateRenderable;
use Erusev\Parsedown\Components\AcquisitioningBlock;
use Erusev\Parsedown\Components\Block;
use Erusev\Parsedown\Configurables\HeaderSlug;
use Erusev\Parsedown\Html\Renderables\Element;
use Erusev\Parsedown\Parsedown;
use Erusev\Parsedown\Parsing\Context;
@@ -88,9 +89,16 @@ final class SetextHeader implements AcquisitioningBlock
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))
);
}