1
0
mirror of https://github.com/erusev/parsedown.git synced 2023-08-10 21:13:06 +03:00

Add convenience instance-based initialisers

This commit is contained in:
Aidan Woods 2019-01-30 19:52:38 +00:00
parent dbc0efeec0
commit 4dee1e9a55
No known key found for this signature in database
GPG Key ID: 9A6A8EFAA512BBB9
3 changed files with 93 additions and 0 deletions

View File

@ -34,6 +34,12 @@
<referencedMethod name="Erusev\Parsedown\Configurables\Breaks::enabled" /> <referencedMethod name="Erusev\Parsedown\Configurables\Breaks::enabled" />
<referencedMethod name="Erusev\Parsedown\State::mergingWith" /> <referencedMethod name="Erusev\Parsedown\State::mergingWith" />
<referencedMethod name="Erusev\Parsedown\Html\Sanitisation\Escaper::htmlElementValue" /> <referencedMethod name="Erusev\Parsedown\Html\Sanitisation\Escaper::htmlElementValue" />
<referencedMethod name="Erusev\Parsedown\Configurables\InlineTypes::addingHighPrecedence" />
<referencedMethod name="Erusev\Parsedown\Configurables\InlineTypes::addingLowPrecedence" />
<referencedMethod name="Erusev\Parsedown\Configurables\BlockTypes::addingMarkedHighPrecedence" />
<referencedMethod name="Erusev\Parsedown\Configurables\BlockTypes::addingMarkedLowPrecedence" />
<referencedMethod name="Erusev\Parsedown\Configurables\BlockTypes::addingUnmarkedHighPrecedence" />
<referencedMethod name="Erusev\Parsedown\Configurables\BlockTypes::addingUnmarkedLowPrecedence" />
</errorLevel> </errorLevel>
</PossiblyUnusedMethod> </PossiblyUnusedMethod>
</issueHandlers> </issueHandlers>

View File

@ -90,6 +90,32 @@ final class BlockTypes implements Configurable
return new self($blockTypes, $this->unmarkedBlockTypes); return new self($blockTypes, $this->unmarkedBlockTypes);
} }
/**
* @param string $marker
* @param array<int, class-string<Block>> $newBlockTypes
* @return self
*/
public function addingMarkedHighPrecedence($marker, array $newBlockTypes)
{
return $this->settingMarked(
$marker,
\array_merge($newBlockTypes, $this->blockTypes[$marker])
);
}
/**
* @param string $marker
* @param array<int, class-string<Block>> $newBlockTypes
* @return self
*/
public function addingMarkedLowPrecedence($marker, array $newBlockTypes)
{
return $this->settingMarked(
$marker,
\array_merge($this->blockTypes[$marker], $newBlockTypes)
);
}
/** /**
* @param array<int, class-string<Block>> $newUnmarkedBlockTypes * @param array<int, class-string<Block>> $newUnmarkedBlockTypes
* @return self * @return self
@ -99,6 +125,28 @@ final class BlockTypes implements Configurable
return new self($this->blockTypes, $newUnmarkedBlockTypes); return new self($this->blockTypes, $newUnmarkedBlockTypes);
} }
/**
* @param array<int, class-string<Block>> $newBlockTypes
* @return self
*/
public function addingUnmarkedHighPrecedence(array $newBlockTypes)
{
return $this->settingUnmarked(
\array_merge($newBlockTypes, $this->unmarkedBlockTypes)
);
}
/**
* @param array<int, class-string<Block>> $newBlockTypes
* @return self
*/
public function addingUnmarkedLowPrecedence(array $newBlockTypes)
{
return $this->settingUnmarked(
\array_merge($this->unmarkedBlockTypes, $newBlockTypes)
);
}
/** /**
* @param array<int, class-string<Block>> $removeBlockTypes * @param array<int, class-string<Block>> $removeBlockTypes
* @return self * @return self

View File

@ -59,6 +59,45 @@ final class InlineTypes implements Configurable
return new self(self::$defaultInlineTypes); return new self(self::$defaultInlineTypes);
} }
/**
* @param string $marker
* @param array<int, class-string<Inline>> $newInlineTypes
* @return self
*/
public function setting($marker, array $newInlineTypes)
{
$inlineTypes = $this->inlineTypes;
$inlineTypes[$marker] = $newInlineTypes;
return new self($inlineTypes);
}
/**
* @param string $marker
* @param array<int, class-string<Inline>> $newInlineTypes
* @return self
*/
public function addingHighPrecedence($marker, array $newInlineTypes)
{
return $this->setting(
$marker,
\array_merge($newInlineTypes, $this->inlineTypes[$marker])
);
}
/**
* @param string $marker
* @param array<int, class-string<Inline>> $newInlineTypes
* @return self
*/
public function addingLowPrecedence($marker, array $newInlineTypes)
{
return $this->setting(
$marker,
\array_merge($this->inlineTypes[$marker], $newInlineTypes)
);
}
/** /**
* @param array<int, class-string<Inline>> $removeInlineTypes * @param array<int, class-string<Inline>> $removeInlineTypes
* @return self * @return self