mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
Add DefinitionBook configurable to replace definition data
This commit is contained in:
parent
c55dbb0d3f
commit
db657952d1
54
src/Configurables/DefinitionBook.php
Normal file
54
src/Configurables/DefinitionBook.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Erusev\Parsedown\Configurables;
|
||||
|
||||
use Erusev\Parsedown\Configurable;
|
||||
|
||||
/**
|
||||
* @psalm-type _Data=array{url: string, title: string|null}
|
||||
*/
|
||||
final class DefinitionBook implements Configurable
|
||||
{
|
||||
/** @var array<string, _Data> */
|
||||
private $book;
|
||||
|
||||
/**
|
||||
* @param array<string, _Data> $book
|
||||
*/
|
||||
public function __construct(array $book = [])
|
||||
{
|
||||
$this->book = $book;
|
||||
}
|
||||
|
||||
/** @return self */
|
||||
public static function default()
|
||||
{
|
||||
return new self;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
* @param _Data $data
|
||||
* @return self
|
||||
*/
|
||||
public function setting($id, array $data)
|
||||
{
|
||||
$book = $this->book;
|
||||
$book[$id] = $data;
|
||||
|
||||
return new self($book);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
* @return _Data|null
|
||||
*/
|
||||
public function lookup($id)
|
||||
{
|
||||
if (isset($this->book[$id])) {
|
||||
return $this->book[$id];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -42,9 +42,6 @@ class Parsedown
|
||||
|
||||
protected function textElements($text)
|
||||
{
|
||||
# make sure no definitions are set
|
||||
$this->DefinitionData = [];
|
||||
|
||||
# iterate through lines to identify blocks
|
||||
return $this->linesElements(Lines::fromTextLines($text, 0));
|
||||
}
|
||||
@ -1739,12 +1736,6 @@ class Parsedown
|
||||
|
||||
private static $instances = [];
|
||||
|
||||
#
|
||||
# Fields
|
||||
#
|
||||
|
||||
protected $DefinitionData;
|
||||
|
||||
#
|
||||
# Read-Only
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user