mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
Default value is intrinsic to a configurable, we can just always
retrieve that.
This commit is contained in:
parent
5a50930cb0
commit
eb90905d27
@ -78,7 +78,7 @@ final class Comment implements ContinuableBlock
|
|||||||
return new Handler(
|
return new Handler(
|
||||||
/** @return Text|RawHtml */
|
/** @return Text|RawHtml */
|
||||||
function (State $State) {
|
function (State $State) {
|
||||||
if ($State->getOrDefault(SafeMode::class)->isEnabled()) {
|
if ($State->get(SafeMode::class)->isEnabled()) {
|
||||||
return new Text($this->html);
|
return new Text($this->html);
|
||||||
} else {
|
} else {
|
||||||
return new RawHtml($this->html);
|
return new RawHtml($this->html);
|
||||||
|
@ -58,10 +58,8 @@ final class Header implements Block
|
|||||||
|
|
||||||
$text = \ltrim($Context->line()->text(), '#');
|
$text = \ltrim($Context->line()->text(), '#');
|
||||||
|
|
||||||
$StrictMode = $State->getOrDefault(StrictMode::class);
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
$StrictMode->isEnabled() && isset($text[0])
|
$State->get(StrictMode::class)->isEnabled() && isset($text[0])
|
||||||
and $text[0] !== ' ' and $text[0] !== "\t"
|
and $text[0] !== ' ' and $text[0] !== "\t"
|
||||||
) {
|
) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -76,9 +76,7 @@ final class Markup implements ContinuableBlock
|
|||||||
return new Handler(
|
return new Handler(
|
||||||
/** @return Element|RawHtml */
|
/** @return Element|RawHtml */
|
||||||
function (State $State) {
|
function (State $State) {
|
||||||
$SafeMode = $State->getOrDefault(SafeMode::class);
|
if ($State->get(SafeMode::class)->isEnabled()) {
|
||||||
|
|
||||||
if ($SafeMode->isEnabled()) {
|
|
||||||
return new Element('p', [], [new Text($this->html)]);
|
return new Element('p', [], [new Text($this->html)]);
|
||||||
} else {
|
} else {
|
||||||
return new RawHtml($this->html);
|
return new RawHtml($this->html);
|
||||||
|
@ -51,7 +51,7 @@ final class Reference implements StateUpdatingBlock
|
|||||||
];
|
];
|
||||||
|
|
||||||
$State = $State->setting(
|
$State = $State->setting(
|
||||||
$State->getOrDefault(DefinitionBook::class)->setting($id, $Data)
|
$State->get(DefinitionBook::class)->setting($id, $Data)
|
||||||
);
|
);
|
||||||
|
|
||||||
return new self($State);
|
return new self($State);
|
||||||
|
@ -83,7 +83,7 @@ final class Image implements Inline
|
|||||||
$attributes['title'] = $title;
|
$attributes['title'] = $title;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($State->getOrDefault(SafeMode::class)->isEnabled()) {
|
if ($State->get(SafeMode::class)->isEnabled()) {
|
||||||
$attributes['src'] = Element::filterUnsafeUrl($attributes['src']);
|
$attributes['src'] = Element::filterUnsafeUrl($attributes['src']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ final class Link implements Inline
|
|||||||
$definition = \strtolower($label);
|
$definition = \strtolower($label);
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = $State->getOrDefault(DefinitionBook::class)->lookup($definition);
|
$data = $State->get(DefinitionBook::class)->lookup($definition);
|
||||||
|
|
||||||
if (! isset($data)) {
|
if (! isset($data)) {
|
||||||
return null;
|
return null;
|
||||||
@ -122,7 +122,7 @@ final class Link implements Inline
|
|||||||
$attributes['title'] = $this->title;
|
$attributes['title'] = $this->title;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($State->getOrDefault(SafeMode::class)->isEnabled()) {
|
if ($State->get(SafeMode::class)->isEnabled()) {
|
||||||
$attributes['href'] = Element::filterUnsafeUrl($attributes['href']);
|
$attributes['href'] = Element::filterUnsafeUrl($attributes['href']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,9 +64,7 @@ final class Markup implements Inline
|
|||||||
return new Handler(
|
return new Handler(
|
||||||
/** @return Text|RawHtml */
|
/** @return Text|RawHtml */
|
||||||
function (State $State) {
|
function (State $State) {
|
||||||
$SafeMode = $State->getOrDefault(SafeMode::class);
|
if ($State->get(SafeMode::class)->isEnabled()) {
|
||||||
|
|
||||||
if ($SafeMode->isEnabled()) {
|
|
||||||
return new Text($this->html);
|
return new Text($this->html);
|
||||||
} else {
|
} else {
|
||||||
return new RawHtml($this->html);
|
return new RawHtml($this->html);
|
||||||
|
@ -43,27 +43,13 @@ final class State
|
|||||||
return new self($State->state + $this->state);
|
return new self($State->state + $this->state);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @template T as Configurable
|
|
||||||
* @template-typeof T $configurableClass
|
|
||||||
* @param class-string<Configurable> $configurableClass
|
|
||||||
* @return T|null
|
|
||||||
* */
|
|
||||||
public function get($configurableClass)
|
|
||||||
{
|
|
||||||
return (isset($this->state[$configurableClass])
|
|
||||||
? $this->state[$configurableClass]
|
|
||||||
: null
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @template T as Configurable
|
* @template T as Configurable
|
||||||
* @template-typeof T $configurableClass
|
* @template-typeof T $configurableClass
|
||||||
* @param class-string<Configurable> $configurableClass
|
* @param class-string<Configurable> $configurableClass
|
||||||
* @return T
|
* @return T
|
||||||
* */
|
* */
|
||||||
public function getOrDefault($configurableClass)
|
public function get($configurableClass)
|
||||||
{
|
{
|
||||||
return (isset($this->state[$configurableClass])
|
return (isset($this->state[$configurableClass])
|
||||||
? $this->state[$configurableClass]
|
? $this->state[$configurableClass]
|
||||||
|
Loading…
Reference in New Issue
Block a user