1
0
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:
Aidan Woods 2019-01-20 02:21:20 +00:00
parent c55dbb0d3f
commit db657952d1
No known key found for this signature in database
GPG Key ID: 9A6A8EFAA512BBB9
2 changed files with 54 additions and 9 deletions

View 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;
}
}

View File

@ -42,9 +42,6 @@ class Parsedown
protected function textElements($text) protected function textElements($text)
{ {
# make sure no definitions are set
$this->DefinitionData = [];
# iterate through lines to identify blocks # iterate through lines to identify blocks
return $this->linesElements(Lines::fromTextLines($text, 0)); return $this->linesElements(Lines::fromTextLines($text, 0));
} }
@ -1739,12 +1736,6 @@ class Parsedown
private static $instances = []; private static $instances = [];
#
# Fields
#
protected $DefinitionData;
# #
# Read-Only # Read-Only