mirror of
https://github.com/erusev/parsedown.git
synced 2024-09-20 03:51:29 +02:00
Cleanup logical operators
This commit is contained in:
parent
19e21f2d1b
commit
d733c262c2
@ -13,6 +13,7 @@ $rules = [
|
|||||||
'braces' => [
|
'braces' => [
|
||||||
'allow_single_line_closure' => true,
|
'allow_single_line_closure' => true,
|
||||||
],
|
],
|
||||||
|
'logical_operators' => true,
|
||||||
'native_constant_invocation' => [
|
'native_constant_invocation' => [
|
||||||
'fix_built_in' => true,
|
'fix_built_in' => true,
|
||||||
],
|
],
|
||||||
|
@ -68,7 +68,7 @@ final class BlockQuote implements ContinuableBlock
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($Context->line()->text()[0] === '>' and \preg_match('/^(>[ \t]?+)(.*+)/', $Context->line()->text(), $matches)) {
|
if ($Context->line()->text()[0] === '>' && \preg_match('/^(>[ \t]?+)(.*+)/', $Context->line()->text(), $matches)) {
|
||||||
$indentOffset = $Context->line()->indentOffset() + $Context->line()->indent() + \strlen($matches[1]);
|
$indentOffset = $Context->line()->indentOffset() + $Context->line()->indent() + \strlen($matches[1]);
|
||||||
|
|
||||||
$recoveredSpaces = 0;
|
$recoveredSpaces = 0;
|
||||||
|
@ -90,7 +90,7 @@ final class FencedCode implements ContinuableBlock
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (($len = \strspn($Context->line()->text(), $this->marker)) >= $this->openerLength
|
if (($len = \strspn($Context->line()->text(), $this->marker)) >= $this->openerLength
|
||||||
and \chop(\substr($Context->line()->text(), $len), ' ') === ''
|
&& \chop(\substr($Context->line()->text(), $len), ' ') === ''
|
||||||
) {
|
) {
|
||||||
$newCode = \substr($newCode, 1);
|
$newCode = \substr($newCode, 1);
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ final class Header implements Block
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
$State->get(StrictMode::class)->isEnabled() && isset($text[0])
|
$State->get(StrictMode::class)->isEnabled() && isset($text[0])
|
||||||
and $text[0] !== ' ' and $text[0] !== "\t"
|
&& $text[0] !== ' ' && $text[0] !== "\t"
|
||||||
) {
|
) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ final class IndentedCode implements ContinuableBlock
|
|||||||
Block $Block = null,
|
Block $Block = null,
|
||||||
State $State = null
|
State $State = null
|
||||||
) {
|
) {
|
||||||
if (isset($Block) and $Block instanceof Paragraph and ! $Context->previousEmptyLines() > 0) {
|
if (isset($Block) && $Block instanceof Paragraph && ! $Context->previousEmptyLines() > 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ final class Reference implements StateUpdatingBlock
|
|||||||
$State = $State ?: new State;
|
$State = $State ?: new State;
|
||||||
|
|
||||||
if (\strpos($Context->line()->text(), ']') !== false
|
if (\strpos($Context->line()->text(), ']') !== false
|
||||||
and \preg_match(
|
&& \preg_match(
|
||||||
'/^\[(.+?)\]:[ ]*+<?(\S+?)>?(?:[ ]+["\'(](.+)["\')])?[ ]*+$/',
|
'/^\[(.+?)\]:[ ]*+<?(\S+?)>?(?:[ ]+["\'(](.+)["\')])?[ ]*+$/',
|
||||||
$Context->line()->text(),
|
$Context->line()->text(),
|
||||||
$matches
|
$matches
|
||||||
|
@ -31,7 +31,7 @@ final class Rule implements Block
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
\substr_count($Context->line()->text(), $marker) >= 3
|
\substr_count($Context->line()->text(), $marker) >= 3
|
||||||
and \chop($Context->line()->text(), " \t$marker") === ''
|
&& \chop($Context->line()->text(), " \t$marker") === ''
|
||||||
) {
|
) {
|
||||||
return new self;
|
return new self;
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ final class SetextHeader implements Block
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($Context->line()->indent() < 4 and \chop(\chop($Context->line()->text(), " \t"), $Context->line()->text()[0]) === '') {
|
if ($Context->line()->indent() < 4 && \chop(\chop($Context->line()->text(), " \t"), $Context->line()->text()[0]) === '') {
|
||||||
$level = $Context->line()->text()[0] === '=' ? 1 : 2;
|
$level = $Context->line()->text()[0] === '=' ? 1 : 2;
|
||||||
|
|
||||||
return new self($Block->text(), $level);
|
return new self($Block->text(), $level);
|
||||||
|
@ -134,9 +134,9 @@ final class TList implements ContinuableBlock
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
$listStart !== '1'
|
$listStart !== '1'
|
||||||
and isset($Block)
|
&& isset($Block)
|
||||||
and $Block instanceof Paragraph
|
&& $Block instanceof Paragraph
|
||||||
and ! $Context->previousEmptyLines() > 0
|
&& ! $Context->previousEmptyLines() > 0
|
||||||
) {
|
) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -162,7 +162,7 @@ final class TList implements ContinuableBlock
|
|||||||
*/
|
*/
|
||||||
public function advance(Context $Context)
|
public function advance(Context $Context)
|
||||||
{
|
{
|
||||||
if ($Context->previousEmptyLines() > 0 and \end($this->Lis)->isEmpty()) {
|
if ($Context->previousEmptyLines() > 0 && \end($this->Lis)->isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,9 +298,9 @@ final class TList implements ContinuableBlock
|
|||||||
$Renderables = $State->applyTo((new Parsedown($State))->lines($Lines));
|
$Renderables = $State->applyTo((new Parsedown($State))->lines($Lines));
|
||||||
|
|
||||||
if (! $Lines->containsBlankLines()
|
if (! $Lines->containsBlankLines()
|
||||||
and isset($Renderables[0])
|
&& isset($Renderables[0])
|
||||||
and $Renderables[0] instanceof Element
|
&& $Renderables[0] instanceof Element
|
||||||
and $Renderables[0]->name() === 'p'
|
&& $Renderables[0]->name() === 'p'
|
||||||
) {
|
) {
|
||||||
$Contents = $Renderables[0]->contents();
|
$Contents = $Renderables[0]->contents();
|
||||||
unset($Renderables[0]);
|
unset($Renderables[0]);
|
||||||
|
@ -52,15 +52,15 @@ final class Table implements ContinuableBlock
|
|||||||
Block $Block = null,
|
Block $Block = null,
|
||||||
State $State = null
|
State $State = null
|
||||||
) {
|
) {
|
||||||
if (! isset($Block) or ! $Block instanceof Paragraph or $Context->previousEmptyLines() > 0) {
|
if (! isset($Block) || ! $Block instanceof Paragraph || $Context->previousEmptyLines() > 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
\strpos($Block->text(), '|') === false
|
\strpos($Block->text(), '|') === false
|
||||||
and \strpos($Context->line()->text(), '|') === false
|
&& \strpos($Context->line()->text(), '|') === false
|
||||||
and \strpos($Context->line()->text(), ':') === false
|
&& \strpos($Context->line()->text(), ':') === false
|
||||||
or \strpos($Block->text(), "\n") !== false
|
|| \strpos($Block->text(), "\n") !== false
|
||||||
) {
|
) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -101,7 +101,7 @@ final class Table implements ContinuableBlock
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (\count($this->alignments) !== 1 and $Context->line()->text()[0] !== '|' and !\strpos($Context->line()->text(), '|')) {
|
if (\count($this->alignments) !== 1 && $Context->line()->text()[0] !== '|' && !\strpos($Context->line()->text(), '|')) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,8 +109,8 @@ final class Table implements ContinuableBlock
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
! \preg_match_all('/(?:(\\\\[|])|[^|`]|`[^`]++`|`)++/', $row, $matches)
|
! \preg_match_all('/(?:(\\\\[|])|[^|`]|`[^`]++`|`)++/', $row, $matches)
|
||||||
or ! isset($matches[0])
|
|| ! isset($matches[0])
|
||||||
or ! \is_array($matches[0])
|
|| ! \is_array($matches[0])
|
||||||
) {
|
) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ final class Email implements Inline
|
|||||||
. $hostnameLabel . '(?:\.' . $hostnameLabel . ')*';
|
. $hostnameLabel . '(?:\.' . $hostnameLabel . ')*';
|
||||||
|
|
||||||
if (\strpos($Excerpt->text(), '>') !== false
|
if (\strpos($Excerpt->text(), '>') !== false
|
||||||
and \preg_match("/^<((mailto:)?$commonMarkEmail)>/i", $Excerpt->text(), $matches)
|
&& \preg_match("/^<((mailto:)?$commonMarkEmail)>/i", $Excerpt->text(), $matches)
|
||||||
) {
|
) {
|
||||||
$url = $matches[1];
|
$url = $matches[1];
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ final class Emphasis implements Inline
|
|||||||
|
|
||||||
$marker = $Excerpt->text()[0] === '*' ? '*' : '_';
|
$marker = $Excerpt->text()[0] === '*' ? '*' : '_';
|
||||||
|
|
||||||
if ($Excerpt->text()[1] === $marker and \preg_match(self::$STRONG_REGEX[$marker], $Excerpt->text(), $matches)) {
|
if ($Excerpt->text()[1] === $marker && \preg_match(self::$STRONG_REGEX[$marker], $Excerpt->text(), $matches)) {
|
||||||
$emphasis = 'strong';
|
$emphasis = 'strong';
|
||||||
} elseif (\preg_match(self::$EM_REGEX[$marker], $Excerpt->text(), $matches)) {
|
} elseif (\preg_match(self::$EM_REGEX[$marker], $Excerpt->text(), $matches)) {
|
||||||
$emphasis = 'em';
|
$emphasis = 'em';
|
||||||
|
@ -34,7 +34,7 @@ final class EscapeSequence implements Inline
|
|||||||
*/
|
*/
|
||||||
public static function build(Excerpt $Excerpt, State $State)
|
public static function build(Excerpt $Excerpt, State $State)
|
||||||
{
|
{
|
||||||
if (isset($Excerpt->text()[1]) and \strpbrk($c = $Excerpt->text()[1], self::SPECIALS) !== false) {
|
if (isset($Excerpt->text()[1]) && \strpbrk($c = $Excerpt->text()[1], self::SPECIALS) !== false) {
|
||||||
return new self($c);
|
return new self($c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,15 +42,15 @@ final class Markup implements Inline
|
|||||||
|
|
||||||
$secondChar = \substr($Excerpt->text(), 1, 1);
|
$secondChar = \substr($Excerpt->text(), 1, 1);
|
||||||
|
|
||||||
if ($secondChar === '/' and \preg_match('/^<\/\w[\w-]*+[ ]*+>/s', $Excerpt->text(), $matches)) {
|
if ($secondChar === '/' && \preg_match('/^<\/\w[\w-]*+[ ]*+>/s', $Excerpt->text(), $matches)) {
|
||||||
return new self($matches[0]);
|
return new self($matches[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($secondChar === '!' and \preg_match('/^<!---?[^>-](?:-?+[^-])*-->/s', $Excerpt->text(), $matches)) {
|
if ($secondChar === '!' && \preg_match('/^<!---?[^>-](?:-?+[^-])*-->/s', $Excerpt->text(), $matches)) {
|
||||||
return new self($matches[0]);
|
return new self($matches[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($secondChar !== ' ' and \preg_match('/^<\w[\w-]*+(?:[ ]*+'.self::HTML_ATT_REGEX.')*+[ ]*+\/?>/s', $Excerpt->text(), $matches)) {
|
if ($secondChar !== ' ' && \preg_match('/^<\w[\w-]*+(?:[ ]*+'.self::HTML_ATT_REGEX.')*+[ ]*+\/?>/s', $Excerpt->text(), $matches)) {
|
||||||
return new self($matches[0]);
|
return new self($matches[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,8 +32,8 @@ final class SpecialCharacter implements Inline
|
|||||||
*/
|
*/
|
||||||
public static function build(Excerpt $Excerpt, State $State)
|
public static function build(Excerpt $Excerpt, State $State)
|
||||||
{
|
{
|
||||||
if (\substr($Excerpt->text(), 1, 1) !== ' ' and \strpos($Excerpt->text(), ';') !== false
|
if (\substr($Excerpt->text(), 1, 1) !== ' ' && \strpos($Excerpt->text(), ';') !== false
|
||||||
and \preg_match('/^&(#?+[0-9a-zA-Z]++);/', $Excerpt->text(), $matches)
|
&& \preg_match('/^&(#?+[0-9a-zA-Z]++);/', $Excerpt->text(), $matches)
|
||||||
) {
|
) {
|
||||||
return new self($matches[1]);
|
return new self($matches[1]);
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ final class Strikethrough implements Inline
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($text[1] === '~' and \preg_match('/^~~(?=\S)(.+?)(?<=\S)~~/', $text, $matches)) {
|
if ($text[1] === '~' && \preg_match('/^~~(?=\S)(.+?)(?<=\S)~~/', $text, $matches)) {
|
||||||
return new self($matches[1], \strlen($matches[0]));
|
return new self($matches[1], \strlen($matches[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,12 +39,12 @@ final class Url implements Inline
|
|||||||
{
|
{
|
||||||
$text = $Excerpt->text();
|
$text = $Excerpt->text();
|
||||||
|
|
||||||
if (\strlen($text) < 2 or \substr($text, 2, 1) !== '/') {
|
if (\strlen($text) < 2 || \substr($text, 2, 1) !== '/') {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (\strpos($Excerpt->context(), 'http') !== false
|
if (\strpos($Excerpt->context(), 'http') !== false
|
||||||
and \preg_match('/\bhttps?+:[\/]{2}[^\s<]+\b\/*+/ui', $Excerpt->context(), $matches, \PREG_OFFSET_CAPTURE)
|
&& \preg_match('/\bhttps?+:[\/]{2}[^\s<]+\b\/*+/ui', $Excerpt->context(), $matches, \PREG_OFFSET_CAPTURE)
|
||||||
) {
|
) {
|
||||||
return new self($matches[0][0], \intval($matches[0][1]));
|
return new self($matches[0][0], \intval($matches[0][1]));
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ final class UrlTag implements Inline
|
|||||||
*/
|
*/
|
||||||
public static function build(Excerpt $Excerpt, State $State)
|
public static function build(Excerpt $Excerpt, State $State)
|
||||||
{
|
{
|
||||||
if (\strpos($Excerpt->text(), '>') !== false and \preg_match('/^<(\w++:\/{2}[^ >]++)>/i', $Excerpt->text(), $matches)) {
|
if (\strpos($Excerpt->text(), '>') !== false && \preg_match('/^<(\w++:\/{2}[^ >]++)>/i', $Excerpt->text(), $matches)) {
|
||||||
return new self($matches[1], \strlen($matches[0]));
|
return new self($matches[1], \strlen($matches[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ final class Parsedown
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($CurrentBlock) and $CurrentBlock instanceof Paragraph) {
|
if (isset($CurrentBlock) && $CurrentBlock instanceof Paragraph) {
|
||||||
$Block = $CurrentBlock->advance($Context);
|
$Block = $CurrentBlock->advance($Context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user