mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
Add easy way to remove Components from InlineTyes and BlockTypes
This commit is contained in:
parent
9f9ef78662
commit
8fe93f30ac
@ -30,6 +30,7 @@
|
||||
<referencedMethod name="Erusev\Parsedown\Html\Renderables\Container::__construct" />
|
||||
<referencedMethod name="Erusev\Parsedown\Configurables\BlockTypes::settingMarked" />
|
||||
<referencedMethod name="Erusev\Parsedown\Configurables\BlockTypes::settingUnmarked" />
|
||||
<referencedMethod name="Erusev\Parsedown\Configurables\BlockTypes::removing" />
|
||||
</errorLevel>
|
||||
</PossiblyUnusedMethod>
|
||||
</issueHandlers>
|
||||
|
@ -6,6 +6,7 @@ use Erusev\Parsedown\AST\Handler;
|
||||
use Erusev\Parsedown\AST\StateRenderable;
|
||||
use Erusev\Parsedown\Components\Inline;
|
||||
use Erusev\Parsedown\Configurables\DefinitionBook;
|
||||
use Erusev\Parsedown\Configurables\InlineTypes;
|
||||
use Erusev\Parsedown\Configurables\SafeMode;
|
||||
use Erusev\Parsedown\Html\Renderables\Element;
|
||||
use Erusev\Parsedown\Html\Renderables\Text;
|
||||
@ -126,10 +127,14 @@ final class Link implements Inline
|
||||
$attributes['href'] = Element::filterUnsafeUrl($attributes['href']);
|
||||
}
|
||||
|
||||
$NewState = $State->setting(
|
||||
$State->get(InlineTypes::class)->removing([Url::class])
|
||||
);
|
||||
|
||||
return new Element(
|
||||
'a',
|
||||
$attributes,
|
||||
$State->applyTo($Parsedown->line($this->label))
|
||||
$State->applyTo((new Parsedown($NewState))->line($this->label))
|
||||
);
|
||||
}
|
||||
);
|
||||
|
@ -100,6 +100,27 @@ final class BlockTypes implements Configurable
|
||||
return new self($this->blockTypes, $newUnmarkedBlockTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string<Block>[] $removeBlockTypes
|
||||
* @return self
|
||||
*/
|
||||
public function removing(array $removeBlockTypes)
|
||||
{
|
||||
return new self(
|
||||
\array_map(
|
||||
/**
|
||||
* @param class-string<Block>[] $blockTypes
|
||||
* @return class-string<Block>[]
|
||||
*/
|
||||
function ($blockTypes) use ($removeBlockTypes) {
|
||||
return \array_diff($blockTypes, $removeBlockTypes);
|
||||
},
|
||||
$this->blockTypes
|
||||
),
|
||||
\array_diff($this->unmarkedBlockTypes, $removeBlockTypes)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $marker
|
||||
* @return class-string<Block>[]
|
||||
|
@ -59,6 +59,24 @@ final class InlineTypes implements Configurable
|
||||
return new self(self::$defaultInlineTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string<Inline>[] $removeInlineTypes
|
||||
* @return self
|
||||
*/
|
||||
public function removing(array $removeInlineTypes)
|
||||
{
|
||||
return new self(\array_map(
|
||||
/**
|
||||
* @param class-string<Inline>[] $inlineTypes
|
||||
* @return class-string<Inline>[]
|
||||
*/
|
||||
function ($inlineTypes) use ($removeInlineTypes) {
|
||||
return \array_diff($inlineTypes, $removeInlineTypes);
|
||||
},
|
||||
$this->inlineTypes
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $marker
|
||||
* @return class-string<Inline>[]
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
namespace Erusev\Parsedown\Tests;
|
||||
|
||||
use Erusev\Parsedown\Components\Inlines\Url;
|
||||
use Erusev\Parsedown\Configurables\InlineTypes;
|
||||
use Erusev\Parsedown\Configurables\StrictMode;
|
||||
use Erusev\Parsedown\Parsedown;
|
||||
use Erusev\Parsedown\State;
|
||||
@ -21,7 +23,8 @@ class CommonMarkTestStrict extends TestCase
|
||||
protected function setUp()
|
||||
{
|
||||
$this->parsedown = new Parsedown(new State([
|
||||
StrictMode::enabled()
|
||||
StrictMode::enabled(),
|
||||
InlineTypes::initial()->removing([Url::class]),
|
||||
]));
|
||||
// $this->parsedown->setUrlsLinked(false);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user