1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-08-07 23:03:00 +03:00

Rolled out reference link updating logic usage

Added test to cover updating of content on reference url change
This commit is contained in:
Dan Brown
2022-08-21 18:05:19 +01:00
parent 0dbf08453f
commit b86ee6d252
5 changed files with 101 additions and 15 deletions

View File

@@ -8,7 +8,7 @@ use BookStack\Entities\Repos\RevisionRepo;
use DOMDocument;
use DOMXPath;
class CrossLinkReplacer
class ReferenceUpdater
{
protected ReferenceFetcher $referenceFetcher;
protected RevisionRepo $revisionRepo;
@@ -53,10 +53,10 @@ class CrossLinkReplacer
return $markdown;
}
$commonLinkRegex = '/(\[.*?\]\()' . preg_quote($oldLink) . '(.*?\))/i';
$commonLinkRegex = '/(\[.*?\]\()' . preg_quote($oldLink, '/') . '(.*?\))/i';
$markdown = preg_replace($commonLinkRegex, '$1' . $newLink . '$2', $markdown);
$referenceLinkRegex = '/(\[.*?\]:\s?)' . preg_quote($oldLink) . '(.*?)($|\s)/i';
$referenceLinkRegex = '/(\[.*?\]:\s?)' . preg_quote($oldLink, '/') . '(.*?)($|\s)/i';
$markdown = preg_replace($referenceLinkRegex, '$1' . $newLink . '$2$3', $markdown);
return $markdown;