Skip to content

Extra space being inserted before link text when using excerpt() #7306

@splorp

Description

@splorp

Description

I have documented a bug that occurs when links are stripped out of blocks of text using the excerpt() method.

If a link is immediately preceded by a character (such as an opening parenthesis, bracket, or quotation mark), when the link gets stripped from a block of text, an extra space is inserted between the preceding character and 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 screenshot below shows the output of the excerpt() method when processing the following text content.

A link surrounded by quotation marks: “(link: / text: Link)”.

A link surrounded by parentheses: ((link: / text: Link)).

A link in the middle of a word: Ultra(link: / text: Link)Modern.

Image

Your setup

Kirby Version
4.8.0

Console output
n/a

Your system (please complete the following information)

  • Device: MacBook Pro
  • OS: macOS 10.13.6 High Sierra / macOS 14.7.6 Sonoma
  • Browser: Vivaldi
  • Version: 6.2.3105.58 / 7.4.3684.50

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions