mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
Substr over indexing string
This commit is contained in:
parent
63a97a926b
commit
117912c373
@ -67,7 +67,10 @@ final class BlockQuote implements ContinuableBlock
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($Context->line()->text()[0] === '>' && \preg_match('/^(>[ \t]?+)(.*+)/', $Context->line()->text(), $matches)) {
|
if (
|
||||||
|
\substr($Context->line()->text(), 0, 1) === '>'
|
||||||
|
&& \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;
|
||||||
|
@ -56,7 +56,7 @@ final class FencedCode implements ContinuableBlock
|
|||||||
Block $Block = null,
|
Block $Block = null,
|
||||||
State $State = null
|
State $State = null
|
||||||
) {
|
) {
|
||||||
$marker = $Context->line()->text()[0];
|
$marker = \substr($Context->line()->text(), 0, 1);
|
||||||
|
|
||||||
$openerLength = \strspn($Context->line()->text(), $marker);
|
$openerLength = \strspn($Context->line()->text(), $marker);
|
||||||
|
|
||||||
|
@ -58,9 +58,11 @@ final class Header implements Block
|
|||||||
|
|
||||||
$text = \ltrim($Context->line()->text(), '#');
|
$text = \ltrim($Context->line()->text(), '#');
|
||||||
|
|
||||||
|
$firstChar = \substr($text, 0, 1);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
$State->get(StrictMode::class)->isEnabled() && isset($text[0])
|
$State->get(StrictMode::class)->isEnabled()
|
||||||
&& $text[0] !== ' ' && $text[0] !== "\t"
|
&& \trim($firstChar, " \t") !== ''
|
||||||
) {
|
) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ final class Rule implements Block
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$marker = $Context->line()->text()[0];
|
$marker = \substr($Context->line()->text(), 0, 1);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
\substr_count($Context->line()->text(), $marker) >= 3
|
\substr_count($Context->line()->text(), $marker) >= 3
|
||||||
|
@ -46,8 +46,17 @@ final class SetextHeader implements Block
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($Context->line()->indent() < 4 && \chop(\chop($Context->line()->text(), " \t"), $Context->line()->text()[0]) === '') {
|
$marker = \substr($Context->line()->text(), 0, 1);
|
||||||
$level = $Context->line()->text()[0] === '=' ? 1 : 2;
|
|
||||||
|
if ($marker !== '=' && $marker !== '-') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
$Context->line()->indent() < 4
|
||||||
|
&& \chop(\chop($Context->line()->text(), " \t"), $marker) === ''
|
||||||
|
) {
|
||||||
|
$level = ($marker === '=' ? 1 : 2);
|
||||||
|
|
||||||
return new self(\trim($Block->text()), $level);
|
return new self(\trim($Block->text()), $level);
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ final class TList implements ContinuableBlock
|
|||||||
State $State = null
|
State $State = null
|
||||||
) {
|
) {
|
||||||
list($type, $pattern) = (
|
list($type, $pattern) = (
|
||||||
$Context->line()->text()[0] <= '-'
|
\substr($Context->line()->text(), 0, 1) <= '-'
|
||||||
? ['ul', '[*+-]']
|
? ['ul', '[*+-]']
|
||||||
: ['ol', '[0-9]{1,9}+[.\)]']
|
: ['ol', '[0-9]{1,9}+[.\)]']
|
||||||
);
|
);
|
||||||
|
@ -101,7 +101,11 @@ final class Table implements ContinuableBlock
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (\count($this->alignments) !== 1 && $Context->line()->text()[0] !== '|' && !\strpos($Context->line()->text(), '|')) {
|
if (
|
||||||
|
\count($this->alignments) !== 1
|
||||||
|
&& \substr($Context->line()->text(), 0, 1) !== '|'
|
||||||
|
&& !\strpos($Context->line()->text(), '|')
|
||||||
|
) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,7 +152,7 @@ final class Table implements ContinuableBlock
|
|||||||
/** @var _Alignment|null */
|
/** @var _Alignment|null */
|
||||||
$alignment = null;
|
$alignment = null;
|
||||||
|
|
||||||
if ($dividerCell[0] === ':') {
|
if (\substr($dividerCell, 0, 1) === ':') {
|
||||||
$alignment = 'left';
|
$alignment = 'left';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ final class Code implements Inline
|
|||||||
*/
|
*/
|
||||||
public static function build(Excerpt $Excerpt, State $State)
|
public static function build(Excerpt $Excerpt, State $State)
|
||||||
{
|
{
|
||||||
$marker = $Excerpt->text()[0];
|
$marker = \substr($Excerpt->text(), 0, 1);
|
||||||
|
|
||||||
if ($marker !== '`') {
|
if ($marker !== '`') {
|
||||||
return null;
|
return null;
|
||||||
|
@ -52,17 +52,20 @@ final class Emphasis implements Inline
|
|||||||
*/
|
*/
|
||||||
public static function build(Excerpt $Excerpt, State $State)
|
public static function build(Excerpt $Excerpt, State $State)
|
||||||
{
|
{
|
||||||
if (! isset($Excerpt->text()[1])) {
|
if (\strlen($Excerpt->text()) < 3) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$marker = $Excerpt->text()[0];
|
$marker = \substr($Excerpt->text(), 0, 1);
|
||||||
|
|
||||||
if ($marker !== '*' && $marker !== '_') {
|
if ($marker !== '*' && $marker !== '_') {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($Excerpt->text()[1] === $marker && \preg_match(self::$STRONG_REGEX[$marker], $Excerpt->text(), $matches)) {
|
if (
|
||||||
|
\substr($Excerpt->text(), 1, 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';
|
||||||
|
@ -33,8 +33,10 @@ 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]) && \strpbrk($c = $Excerpt->text()[1], self::SPECIALS) !== false) {
|
$char = \substr($Excerpt->text(), 1, 1);
|
||||||
return new self($c);
|
|
||||||
|
if ($char !== '' && \strpbrk($char, self::SPECIALS) !== false) {
|
||||||
|
return new self($char);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -41,7 +41,7 @@ final class Strikethrough implements Inline
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($text[1] === '~' && \preg_match('/^~~(?=\S)(.+?)(?<=\S)~~/', $text, $matches)) {
|
if (\substr($text, 1, 1) === '~' && \preg_match('/^~~(?=\S)(.+?)(?<=\S)~~/', $text, $matches)) {
|
||||||
return new self($matches[1], \strlen($matches[0]));
|
return new self($matches[1], \strlen($matches[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ final class Parsedown
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$marker = $Line->text()[0];
|
$marker = \substr($Line->text(), 0, 1);
|
||||||
|
|
||||||
$potentialBlockTypes = \array_merge(
|
$potentialBlockTypes = \array_merge(
|
||||||
$State->get(BlockTypes::class)->unmarked(),
|
$State->get(BlockTypes::class)->unmarked(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user