-
-
Notifications
You must be signed in to change notification settings - Fork 180
Description
Description
I previously documented a bug (#7306) that occurs when links are stripped out of blocks of text using the excerpt()
method. I also submitted a related bug for Kirby 3 (#4301).
This issue was partially addressed in the Kirby 5.1.0 release, but has not been completely fixed in either 5.1.0 or 5.1.1 … and in some cases the problem has been made worse.
If a link is immediately preceded by a character (such as an opening parenthesis, bracket, quotation mark, or other glyph), when the link gets stripped from a block of text, an extra space is inserted between the preceding character and the original linked text.
In Kirby 5.1.0 and 5.1.1, the problem has been fixed in situations involving parentheses and brackets. In these particular cases the extra preceding space has been eliminated from the excerpt.
However, in situations involving any other character (quotation marks, guillemots, &c.), the extra preceding space has been changed to an extra space trailing the original linked text.
In the case of a link appearing within a word, there are now extra spaces inserted on both sides of the original linked text.
To reproduce
I’m using the following code in my template, links in the text field are formatted using Markdown.
<?php echo $result->text()->excerpt(200) ?>
However, the same issue can be reproduced using:
<?php echo Str::excerpt('«<a href="https://getkirby.com/">Get Kirby</a>», 200) ?>
This example returns:
«Get Kirby »
Expected behavior
When links are stripped out of text using the excerpt()
method, extra spaces should not be added between an immediately preceded character and the link text.
The expected text being returned should be:
«Get Kirby»
Screenshots
The screenshots below show the output of the excerpt()
method when processing the following text content in Kirby versions 5.0.4, 5.1.0, and 5.1.1 respectively.
A link surrounded by single quotation marks: ‘(link: / text: Link)’.
A link surrounded by double quotation marks: “(link: / text: Link)”.
A link surrounded by single guillemots: ‹(link: / text: Link)›.
A link surrounded by double guillemots: «(link: / text: Link)».
A link surrounded by brackets: [(link: / text: Link)].
A link surrounded by parentheses: ((link: / text: Link)).
A link in the middle of a word: Ultra(link: / text: Link)Modern.
Kirby 5.0.4

Kirby 5.1.0

Kirby 5.1.1

Setup
Kirby Version
5.0.4 / 5.1.0 / 5.1.1
Console output
n/a
System
- Device: MacBook Pro
- OS: macOS 10.13.6 High Sierra / macOS 14.8 Sonoma
- Browser: Vivaldi
- Version: 6.2.3105.58 / 7.6.3797.52