Skip to content

Commit 5f74c0d

Browse files
committed
removed standalone [ref] link syntax (BC break)
1 parent f272b76 commit 5f74c0d

14 files changed

Lines changed: 33 additions & 212 deletions

phpstan-baseline.neon

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ parameters:
1212
count: 1
1313
path: src/Bridges/Latte/TexyNode.php
1414

15-
-
16-
message: '#^Parameter \#1 \$URL of class Texy\\Link constructor expects string, string\|null given\.$#'
17-
identifier: argument.type
18-
count: 1
19-
path: src/Texy/Modules/FigureModule.php
20-
2115
-
2216
message: '#^Parameter \#1 \$string of function substr expects string, string\|null given\.$#'
2317
identifier: argument.type
@@ -30,18 +24,6 @@ parameters:
3024
count: 1
3125
path: src/Texy/Modules/HtmlOutputModule.php
3226

33-
-
34-
message: '#^Parameter \#1 \$URL of class Texy\\Link constructor expects string, string\|null given\.$#'
35-
identifier: argument.type
36-
count: 1
37-
path: src/Texy/Modules/ImageModule.php
38-
39-
-
40-
message: '#^Parameter \#1 \$URL of class Texy\\Link constructor expects string, string\|null given\.$#'
41-
identifier: argument.type
42-
count: 1
43-
path: src/Texy/Modules/LinkModule.php
44-
4527
-
4628
message: '#^Parameter \#3 \$subject of function str_replace expects array\<string\>\|string, string\|null given\.$#'
4729
identifier: argument.type

src/Texy/Configurator.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ public static function safeMode(Texy $texy): void
6969
*/
7070
public static function disableLinks(Texy $texy): void
7171
{
72-
$texy->allowed['link/reference'] = false;
7372
$texy->allowed['link/email'] = false;
7473
$texy->allowed['link/url'] = false;
7574
$texy->allowed['link/definition'] = false;

src/Texy/Link.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ final class Link
3737
public ?string $name = null;
3838

3939

40-
public function __construct(string $URL)
40+
public function __construct(?string $URL)
4141
{
4242
$this->URL = $URL;
43-
$this->raw = $URL;
43+
$this->raw = $URL ?? '';
4444
$this->modifier = new Modifier;
4545
}
4646

src/Texy/Modules/LinkModule.php

Lines changed: 1 addition & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
use Texy;
1111
use Texy\HandlerInvocation;
12-
use Texy\InlineParser;
1312
use Texy\Link;
1413
use Texy\Patterns;
1514
use Texy\Regexp;
@@ -30,34 +29,16 @@ final class LinkModule extends Texy\Module
3029
/** @var array<string, Link> link references */
3130
private array $references = [];
3231

33-
/** @var array<string, true> */
34-
private static array $livelock;
35-
3632

3733
public function __construct(
3834
private Texy\Texy $texy,
3935
) {
4036
$texy->allowed['link/definition'] = true;
41-
$texy->addHandler('newReference', $this->solveNewReference(...));
42-
$texy->addHandler('linkReference', $this->solve(...));
4337
}
4438

4539

4640
public function beforeParse(string &$text): void
4741
{
48-
// [reference]
49-
$this->texy->registerLinePattern(
50-
$this->parseReference(...),
51-
'~(
52-
\[
53-
[^\[\]*\n' . Patterns::MARK . ']++ # reference
54-
]
55-
)~U',
56-
'link/reference',
57-
);
58-
59-
self::$livelock = [];
60-
6142
// [la trine]: http://www.latrine.cz/ text odkazu .(title)[class]{style}
6243
if (!empty($this->texy->allowed['link/definition'])) {
6344
$text = Texy\Regexp::replace(
@@ -100,47 +81,6 @@ private function parseDefinition(array $matches): string
10081
}
10182

10283

103-
/**
104-
* Parses [ref]
105-
* @param array<?string> $matches
106-
*/
107-
public function parseReference(InlineParser $parser, array $matches): Texy\HtmlElement|string|null
108-
{
109-
/** @var array{string, string} $matches */
110-
[, $mRef] = $matches;
111-
// [1] => [ref]
112-
113-
$texy = $this->texy;
114-
$name = substr($mRef, 1, -1);
115-
$link = $this->getReference($name);
116-
117-
if (!$link) {
118-
return $texy->invokeAroundHandlers('newReference', $parser, [$name]);
119-
}
120-
121-
$link->type = $link::BRACKET;
122-
123-
if ($link->label != '') { // null or ''
124-
// prevent circular references
125-
assert($link->name !== null);
126-
if (isset(self::$livelock[$link->name])) {
127-
$content = $link->label;
128-
} else {
129-
self::$livelock[$link->name] = true;
130-
$lineParser = $texy->createInlineParser();
131-
$el = new Texy\HtmlElement(null, $lineParser->parse($link->label));
132-
$content = $el->toString($texy);
133-
unset(self::$livelock[$link->name]);
134-
}
135-
} else {
136-
$content = $texy->autolinkModule->textualUrl($link);
137-
$content = $texy->protect($content, $texy::CONTENT_TEXTUAL);
138-
}
139-
140-
return $texy->invokeAroundHandlers('linkReference', $parser, [$link, $content]);
141-
}
142-
143-
14484
/**
14585
* Adds a user-defined link definition (persists across process() calls).
14686
*/
@@ -223,7 +163,7 @@ public function factoryLink(string $dest, ?string $mMod, ?string $label): Link
223163

224164

225165
/**
226-
* Finish invocation - generates <a> element.
166+
* Generates <a> element from Link.
227167
*/
228168
public function solve(
229169
?HandlerInvocation $invocation,
@@ -267,15 +207,6 @@ public function solve(
267207
}
268208

269209

270-
/**
271-
* Handler for undefined references.
272-
*/
273-
private function solveNewReference(HandlerInvocation $invocation, string $name): void
274-
{
275-
// no change
276-
}
277-
278-
279210
/**
280211
* Checks and corrects URL in Link.
281212
*/

tests/Texy/expected/block-types.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
space space
2-
<p>/--.<a href="https://texy.nette.org/" title="The best text → HTML converter and formatter">Texy!</a> te st \--</p>
2+
<p>/--.[texy] te st \--</p>
33

44
<pre class="texy">te
55
st</pre>

tests/Texy/expected/link-combined-classes.html

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,6 @@ <h1>Odkazy</h1>
3535

3636
<li>Referenční odkaz <a href="/trine/?a=45" title="title">php Fashion</a>?</li>
3737

38-
<li>Čistě referenční odkaz <a href="http://phpfashion.com/" title="title">text <em>o</em>dkazu</a></li>
39-
40-
<li>Čistě referenční odkaz <a href="/trine/" title="title">/trine/</a></li>
41-
42-
<li>Čistě referenční odkaz <a href="xxx/./trine/">./trine/</a></li>
43-
44-
<li>Čistě referenční odkaz <a href="mailto:dave&#64;example.com" title="title">dave&#64;<!-- -->example.com</a></li>
45-
4638
<li>wiki link <a href="http://texy.info">Texy</a></li>
4739

4840
<li>wiki link <a href="http://texy.info">Texy</a></li>
@@ -66,14 +58,6 @@ <h1>Obrázkové odkazy:</h1>
6658
<li>Referenční odkaz <a href="../images/texy.jpg" title="altX">obrazek</a></li>
6759

6860
<li>Referenční odkaz <a href="../images/texy.jpg">obrazek</a></li>
69-
70-
<li>Čistě referenční odkaz <a href="xxx/[*texy-big.jpg*]" title="title">text</a></li>
71-
72-
<li>Čistě referenční odkaz <a href="xxx/[*">texy-big.jpg *] text</a></li>
73-
74-
<li>Čistě referenční odkaz <a href="xxx/[*texy-big.jpg*]">[*texy-big.jpg*]</a></li>
75-
76-
<li>Čistě referenční odkaz <a href="xxx/[*obrazek3*]" title="test"><img src="../images/texy.jpg" alt="altX"></a></li>
7761
</ul>
7862

7963
<h1>Odkazující obrázky:</h1>
@@ -83,7 +67,7 @@ <h1>Odkazující obrázky:</h1>
8367

8468
<li>Klasický odkaz <a href="mailto:dave&#64;example.com"><img src="../images/texy.jpg" class="left" alt="title"></a>x</li>
8569

86-
<li>Referenční odkaz <a href="xxx/[*texy-big.jpg*]" title="title">text</a>:<a href="http://phpfashion.com/" title="title">text <em>o</em>dkazu</a></li>
70+
<li>Referenční odkaz [neobrazek1]:[php Fashion1]</li>
8771

8872
<li>Referenční odkaz <a href="../images/texy.jpg">php Fashion</a></li>
8973

tests/Texy/expected/link-combined-safe.html

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,6 @@ <h1>Odkazy</h1>
3535

3636
<li>Referenční odkaz <a href="xxx/php Fashion2?a=45">php Fashion</a>?</li>
3737

38-
<li>Čistě referenční odkaz [php Fashion1]</li>
39-
40-
<li>Čistě referenční odkaz [php Fashion2]</li>
41-
42-
<li>Čistě referenční odkaz [php Fashion3]</li>
43-
44-
<li>Čistě referenční odkaz [email]</li>
45-
4638
<li>wiki link <a href="http://texy.info" rel="nofollow">Texy</a></li>
4739

4840
<li>wiki link <a href="http://texy.info" rel="nofollow">Texy</a></li>
@@ -66,14 +58,6 @@ <h1>Obrázkové odkazy:</h1>
6658
<li>Referenční odkaz <a href="../images/texy.jpg" title="altX">obrazek</a></li>
6759

6860
<li>Referenční odkaz <a href="../images/texy.jpg">obrazek</a></li>
69-
70-
<li>Čistě referenční odkaz [neobrazek1]</li>
71-
72-
<li>Čistě referenční odkaz [neobrazek2]</li>
73-
74-
<li>Čistě referenční odkaz [neobrazek3]</li>
75-
76-
<li>Čistě referenční odkaz [neobrazek4]</li>
7761
</ul>
7862

7963
<h1>Odkazující obrázky:</h1>

tests/Texy/expected/link-combined.html

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,6 @@ <h1>Odkazy</h1>
3535

3636
<li>Referenční odkaz <a href="/trine/?a=45" title="title">php Fashion</a>?</li>
3737

38-
<li>Čistě referenční odkaz <a href="http://phpfashion.com/" title="title" class="aa">text <em>o</em>dkazu</a></li>
39-
40-
<li>Čistě referenční odkaz <a href="/trine/" title="title">/trine/</a></li>
41-
42-
<li>Čistě referenční odkaz <a href="xxx/./trine/">./trine/</a></li>
43-
44-
<li>Čistě referenční odkaz <a href="mailto:dave&#64;example.com" title="title">dave&#64;<!-- -->example.com</a></li>
45-
4638
<li>wiki link <a href="http://texy.info">Texy</a></li>
4739

4840
<li>wiki link <a href="http://texy.info">Texy</a></li>
@@ -66,14 +58,6 @@ <h1>Obrázkové odkazy:</h1>
6658
<li>Referenční odkaz <a href="../images/texy.jpg" title="altX">obrazek</a></li>
6759

6860
<li>Referenční odkaz <a href="../images/texy.jpg">obrazek</a></li>
69-
70-
<li>Čistě referenční odkaz <a href="xxx/[*texy-big.jpg*]" title="title">text</a></li>
71-
72-
<li>Čistě referenční odkaz <a href="xxx/[*">texy-big.jpg *] text</a></li>
73-
74-
<li>Čistě referenční odkaz <a href="xxx/[*texy-big.jpg*]">[*texy-big.jpg*]</a></li>
75-
76-
<li>Čistě referenční odkaz <a href="xxx/[*obrazek3*]" title="test"><img src="../images/texy.jpg" alt="altX"></a></li>
7761
</ul>
7862

7963
<h1>Odkazující obrázky:</h1>
@@ -83,7 +67,7 @@ <h1>Odkazující obrázky:</h1>
8367

8468
<li>Klasický odkaz <a href="mailto:dave&#64;example.com"><img src="../images/texy.jpg" class="class left" alt="title"></a>x</li>
8569

86-
<li>Referenční odkaz <a href="xxx/[*texy-big.jpg*]" title="title">text</a>:<a href="http://phpfashion.com/" title="title" class="aa">text <em>o</em>dkazu</a></li>
70+
<li>Referenční odkaz [neobrazek1]:[php Fashion1]</li>
8771

8872
<li>Referenční odkaz <a href="../images/texy.jpg">php Fashion</a></li>
8973

tests/Texy/expected/showcase.html

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,6 @@ <h2>Links</h2>
100100
<h3>using references</h3>
101101

102102
<ul>
103-
<li>Look at <a href="http://texy.nette.org/"
104-
title="this is homepage">Texy!</a></li>
105-
106-
<li>My address is <a
107-
href="mailto:me&#64;example.com">me&#64;<!-- -->example.com</a></li>
108-
109103
<li>What about <a href="http://texy.nette.org/"
110104
title="this is homepage">this</a> site?</li>
111105
</ul>

tests/Texy/expected/showcase.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,6 @@ Links
9494
using references
9595

9696

97-
Look at Texy!
98-
99-
My address is me@example.com
100-
10197
What about this site?
10298

10399

0 commit comments

Comments
 (0)