|
|
@@ -2361,7 +2361,9 @@ class MDAbbreviationReader extends MDReader {
|
|
2361
|
2361
|
if ($index === false) continue;
|
|
2362
|
2362
|
$prefix = substr($text, 0, $index);
|
|
2363
|
2363
|
$suffix = substr($text, $index + strlen($abbreviation));
|
|
2364
|
|
- array_splice($elems, $i, 1, [$prefix, new MDAbbreviationNode($abbreviation, $definition), $suffix]);
|
|
|
2364
|
+ array_splice($elems, $i, 1, [$prefix,
|
|
|
2365
|
+ new MDAbbreviationNode($abbreviation, $definition),
|
|
|
2366
|
+ $suffix]);
|
|
2365
|
2367
|
$i = -1; // start over
|
|
2366
|
2368
|
$changed = true;
|
|
2367
|
2369
|
break;
|
|
|
@@ -2441,7 +2443,9 @@ class MDSimplePairInlineReader extends MDReader {
|
|
2441
|
2443
|
* content string instead of parsed `MDNode`s
|
|
2442
|
2444
|
* @return bool `true` if substitution was performed, `false` if not
|
|
2443
|
2445
|
*/
|
|
2444
|
|
- public function attemptPair(MDState $state, int $pass, array &$tokens, string $nodeClass, MDTokenType $delimiter, int $count=1, bool $plaintext=false): bool {
|
|
|
2446
|
+ public function attemptPair(MDState $state, int $pass, array &$tokens,
|
|
|
2447
|
+ string $nodeClass, MDTokenType $delimiter, int $count=1,
|
|
|
2448
|
+ bool $plaintext=false): bool {
|
|
2445
|
2449
|
// We do four passes. #1: doubles without inner tokens, #2: singles
|
|
2446
|
2450
|
// without inner tokens, #3: doubles with paired inner tokens,
|
|
2447
|
2451
|
// #4: singles with paired inner tokens
|
|
|
@@ -2449,9 +2453,11 @@ class MDSimplePairInlineReader extends MDReader {
|
|
2449
|
2453
|
if ($count > 1 && $pass != 1 && $pass != 3) return false;
|
|
2450
|
2454
|
$delimiters = array_fill(0, $count, $delimiter);
|
|
2451
|
2455
|
$isFirstOfMultiplePasses = $this->substitutionPassCount() > 1 && $pass == 1;
|
|
2452
|
|
- $match = MDToken::findPairedTokens($tokens, $delimiters, $delimiters, function($content) use ($nodeClass, $isFirstOfMultiplePasses, $delimiter) {
|
|
|
2456
|
+ $match = MDToken::findPairedTokens($tokens, $delimiters, $delimiters,
|
|
|
2457
|
+ function($content) use ($nodeClass, $isFirstOfMultiplePasses, $delimiter) {
|
|
2453
|
2458
|
$firstType = $content[0] instanceof MDToken ? $content[0]->type : null;
|
|
2454
|
|
- $lastType = $content[sizeof($content) - 1] instanceof MDToken ? $content[sizeof($content) - 1]->type : null;
|
|
|
2459
|
+ $lastType = $content[sizeof($content) - 1] instanceof MDToken ?
|
|
|
2460
|
+ $content[sizeof($content) - 1]->type : null;
|
|
2455
|
2461
|
if ($firstType == MDTokenType::Whitespace) return false;
|
|
2456
|
2462
|
if ($lastType == MDTokenType::Whitespace) return false;
|
|
2457
|
2463
|
foreach ($content as $token) {
|
|
|
@@ -2470,7 +2476,8 @@ class MDSimplePairInlineReader extends MDReader {
|
|
2470
|
2476
|
if ($match === null) return false;
|
|
2471
|
2477
|
$state->checkExecutionTime();
|
|
2472
|
2478
|
if ($plaintext) {
|
|
2473
|
|
- $content = implode('', array_map(fn($token) => $token instanceof MDToken ? $token->original : $token->toPlaintext($state), $match->contentTokens));
|
|
|
2479
|
+ $content = implode('', array_map(fn($token) => $token instanceof MDToken ?
|
|
|
2480
|
+ $token->original : $token->toPlaintext($state), $match->contentTokens));
|
|
2474
|
2481
|
} else {
|
|
2475
|
2482
|
$content = $state->tokensToNodes($match->contentTokens);
|
|
2476
|
2483
|
}
|
|
|
@@ -2683,19 +2690,23 @@ class MDLinkReader extends MDReader {
|
|
2683
|
2690
|
}
|
|
2684
|
2691
|
|
|
2685
|
2692
|
public function substituteTokens(MDState $state, int $pass, array &$tokens): bool {
|
|
2686
|
|
- if ($match = MDToken::findFirstTokens($tokens, [ MDTokenType::Label, MDTokenType::META_OptionalWhitespace, MDTokenType::URL ])) {
|
|
|
2693
|
+ if ($match = MDToken::findFirstTokens($tokens, [ MDTokenType::Label,
|
|
|
2694
|
+ MDTokenType::META_OptionalWhitespace, MDTokenType::URL ])) {
|
|
2687
|
2695
|
$text = $match->tokens[0]->content;
|
|
2688
|
2696
|
$url = $match->tokens[sizeof($match->tokens) - 1]->content;
|
|
2689
|
2697
|
$title = $match->tokens[sizeof($match->tokens) - 1]->extra;
|
|
2690
|
|
- array_splice($tokens, $match->index, sizeof($match->tokens), [new MDLinkNode($url, $state->inlineMarkdownToNode($text), $title)]);
|
|
|
2698
|
+ array_splice($tokens, $match->index, sizeof($match->tokens),
|
|
|
2699
|
+ [new MDLinkNode($url, $state->inlineMarkdownToNode($text), $title)]);
|
|
2691
|
2700
|
return true;
|
|
2692
|
2701
|
}
|
|
2693
|
|
- if ($match = MDToken::findFirstTokens($tokens, [ MDTokenType::Label, MDTokenType::META_OptionalWhitespace, MDTokenType::Email ])) {
|
|
|
2702
|
+ if ($match = MDToken::findFirstTokens($tokens, [ MDTokenType::Label,
|
|
|
2703
|
+ MDTokenType::META_OptionalWhitespace, MDTokenType::Email ])) {
|
|
2694
|
2704
|
$text = $match->tokens[0]->content;
|
|
2695
|
2705
|
$email = $match->tokens[sizeof($match->tokens) - 1]->content;
|
|
2696
|
2706
|
$url = "mailto:{$email}";
|
|
2697
|
2707
|
$title = $match->tokens[sizeof($match->tokens) - 1]->extra;
|
|
2698
|
|
- array_splice($tokens, $match->index, sizeof($match->tokens), [new MDLinkNode($url, $state->inlineMarkdownToNodes($text), $title)]);
|
|
|
2708
|
+ array_splice($tokens, $match->index, sizeof($match->tokens),
|
|
|
2709
|
+ [new MDLinkNode($url, $state->inlineMarkdownToNodes($text), $title)]);
|
|
2699
|
2710
|
return true;
|
|
2700
|
2711
|
}
|
|
2701
|
2712
|
if ($match = MDToken::findFirstTokens($tokens, [ MDTokenType::SimpleEmail ])) {
|
|
|
@@ -2745,10 +2756,12 @@ class MDReferencedLinkReader extends MDLinkReader {
|
|
2745
|
2756
|
}
|
|
2746
|
2757
|
|
|
2747
|
2758
|
public function substituteTokens(MDState $state, int $pass, array &$tokens): bool {
|
|
2748
|
|
- if ($match = MDToken::findFirstTokens($tokens, [ MDTokenType::Label, MDTokenType::META_OptionalWhitespace, MDTokenType::Label ])) {
|
|
|
2759
|
+ if ($match = MDToken::findFirstTokens($tokens, [ MDTokenType::Label,
|
|
|
2760
|
+ MDTokenType::META_OptionalWhitespace, MDTokenType::Label ])) {
|
|
2749
|
2761
|
$text = $match->tokens[0]->content;
|
|
2750
|
2762
|
$ref = $match->tokens[sizeof($match->tokens) - 1]->content;
|
|
2751
|
|
- array_splice($tokens, $match->index, sizeof($match->tokens), [new MDReferencedLinkNode($ref, $state->inlineMarkdownToNodes($text))]);
|
|
|
2763
|
+ array_splice($tokens, $match->index, sizeof($match->tokens),
|
|
|
2764
|
+ [new MDReferencedLinkNode($ref, $state->inlineMarkdownToNodes($text))]);
|
|
2752
|
2765
|
return true;
|
|
2753
|
2766
|
}
|
|
2754
|
2767
|
return false;
|
|
|
@@ -2768,7 +2781,8 @@ class MDImageReader extends MDLinkReader {
|
|
2768
|
2781
|
}
|
|
2769
|
2782
|
|
|
2770
|
2783
|
public function substituteTokens(MDState $state, int $pass, array &$tokens): bool {
|
|
2771
|
|
- if ($match = MDToken::findFirstTokens($tokens, [ MDTokenType::Bang, MDTokenType::Label, MDTokenType::META_OptionalWhitespace, MDTokenType::URL ])) {
|
|
|
2784
|
+ if ($match = MDToken::findFirstTokens($tokens, [ MDTokenType::Bang,
|
|
|
2785
|
+ MDTokenType::Label, MDTokenType::META_OptionalWhitespace, MDTokenType::URL ])) {
|
|
2772
|
2786
|
$alt = $match->tokens[1]->content;
|
|
2773
|
2787
|
$url = $match->tokens[sizeof($match->tokens) - 1]->content;
|
|
2774
|
2788
|
$title = $match->tokens[sizeof($match->tokens) - 1]->extra;
|
|
|
@@ -2804,10 +2818,12 @@ class MDReferencedImageReader extends MDReferencedLinkReader {
|
|
2804
|
2818
|
}
|
|
2805
|
2819
|
|
|
2806
|
2820
|
public function substituteTokens(MDState $state, int $pass, array &$tokens): bool {
|
|
2807
|
|
- if ($match = MDToken::findFirstTokens($tokens, [ MDTokenType::Bang, MDTokenType::Label, MDTokenType::META_OptionalWhitespace, MDTokenType::Label ])) {
|
|
|
2821
|
+ if ($match = MDToken::findFirstTokens($tokens, [ MDTokenType::Bang,
|
|
|
2822
|
+ MDTokenType::Label, MDTokenType::META_OptionalWhitespace, MDTokenType::Label ])) {
|
|
2808
|
2823
|
$alt = $match->tokens[1]->content;
|
|
2809
|
2824
|
$ref = $match->tokens[sizeof($match->tokens) - 1]->content;
|
|
2810
|
|
- array_splice($tokens, $match->index, sizeof($match->tokens), [new MDReferencedImageNode($ref, $alt)]);
|
|
|
2825
|
+ array_splice($tokens, $match->index, sizeof($match->tokens),
|
|
|
2826
|
+ [new MDReferencedImageNode($ref, $alt)]);
|
|
2811
|
2827
|
return true;
|
|
2812
|
2828
|
}
|
|
2813
|
2829
|
return false;
|
|
|
@@ -2933,7 +2949,8 @@ class MDNode {
|
|
2933
|
2949
|
if (!($elem instanceof MDNode)) {
|
|
2934
|
2950
|
$thisClassName = MDUtils::typename($this);
|
|
2935
|
2951
|
$elemClassName = MDUtils::typename($elem);
|
|
2936
|
|
- throw new Error("{$thisClassName} expects children of type MDNode[] or MDNode, got array with {$elemClassName} element");
|
|
|
2952
|
+ throw new Error("{$thisClassName} expects children of type " .
|
|
|
2953
|
+ "MDNode[] or MDNode, got array with {$elemClassName} element");
|
|
2937
|
2954
|
}
|
|
2938
|
2955
|
}
|
|
2939
|
2956
|
$this->children = $children;
|
|
|
@@ -2942,7 +2959,8 @@ class MDNode {
|
|
2942
|
2959
|
} else {
|
|
2943
|
2960
|
$thisClassName = MDUtils::typename($this);
|
|
2944
|
2961
|
$elemClassName = MDUtils::typename($children);
|
|
2945
|
|
- throw new Error("{$thisClassName} expects children of type MDNode[] or MDNode, got {$elemClassName}");
|
|
|
2962
|
+ throw new Error("{$thisClassName} expects children of type MDNode[] " .
|
|
|
2963
|
+ "or MDNode, got {$elemClassName}");
|
|
2946
|
2964
|
}
|
|
2947
|
2965
|
}
|
|
2948
|
2966
|
|
|
|
@@ -3418,11 +3436,13 @@ class MDFootnoteListNode extends MDBlockNode {
|
|
3418
|
3436
|
if (!$content) continue;
|
|
3419
|
3437
|
$footnoteId = $this->footnoteId($state, $symbol);
|
|
3420
|
3438
|
$contentHTML = MDNode::arrayToHTML($content, $state);
|
|
3421
|
|
- $html .= "<li value=\"{$footnoteId}\" id=\"{$state->root()->elementIdPrefix}footnote_{$footnoteId}\">{$contentHTML}";
|
|
|
3439
|
+ $html .= "<li value=\"{$footnoteId}\" id=\"" .
|
|
|
3440
|
+ "{$state->root()->elementIdPrefix}footnote_{$footnoteId}\">{$contentHTML}";
|
|
3422
|
3441
|
$uniques = $footnoteUniques[$symbol] ?? null;
|
|
3423
|
3442
|
if ($uniques) {
|
|
3424
|
3443
|
foreach ($uniques as $unique) {
|
|
3425
|
|
- $html .= " <a href=\"#{$state->root()->elementIdPrefix}footnoteref_{$unique}\" class=\"footnote-backref\">↩︎</a>";
|
|
|
3444
|
+ $html .= " <a href=\"#{$state->root()->elementIdPrefix}footnoteref_{$unique}\"" .
|
|
|
3445
|
+ " class=\"footnote-backref\">↩︎</a>";
|
|
3426
|
3446
|
}
|
|
3427
|
3447
|
}
|
|
3428
|
3448
|
$html .= "</li>\n";
|
|
|
@@ -3597,8 +3617,10 @@ class MDFootnoteNode extends MDInlineNode {
|
|
3597
|
3617
|
|
|
3598
|
3618
|
public function toHTML(MDState $state): string {
|
|
3599
|
3619
|
if ($this->footnoteId !== null) {
|
|
3600
|
|
- return "<sup class=\"footnote\" id=\"{$state->root()->elementIdPrefix}footnoteref_{$this->occurrenceId}\"" . $this->htmlAttributes() . ">" .
|
|
3601
|
|
- "<a href=\"#{$state->root()->elementIdPrefix}footnote_{$this->footnoteId}\">" . htmlentities($this->displaySymbol ?? $this->symbol) . "</a></sup>";
|
|
|
3620
|
+ return "<sup class=\"footnote\" id=\"{$state->root()->elementIdPrefix}footnoteref_{$this->occurrenceId}\"" .
|
|
|
3621
|
+ $this->htmlAttributes() . ">" .
|
|
|
3622
|
+ "<a href=\"#{$state->root()->elementIdPrefix}footnote_{$this->footnoteId}\">" .
|
|
|
3623
|
+ htmlentities($this->displaySymbol ?? $this->symbol) . "</a></sup>";
|
|
3602
|
3624
|
}
|
|
3603
|
3625
|
return "<!--FNREF:{{$this->symbol}}-->";
|
|
3604
|
3626
|
}
|