Link rendering: Add support for UrlMode parameter in HtmlLocalLinkParser (port to 16) (#20207)
* Add support for UrlMode parameter in HtmlLocalLinkParser (port of #20200 from 13 to 16). * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Kenn Jacobsen <kja@umbraco.dk>
This commit is contained in:
@@ -40,7 +40,7 @@ public class TextStringValueConverter : PropertyValueConverterBase, IDeliveryApi
|
||||
var sourceString = source.ToString();
|
||||
|
||||
// ensures string is parsed for {localLink} and URLs are resolved correctly
|
||||
sourceString = _linkParser.EnsureInternalLinks(sourceString!, preview);
|
||||
sourceString = _linkParser.EnsureInternalLinks(sourceString!);
|
||||
sourceString = _urlParser.EnsureUrls(sourceString);
|
||||
|
||||
return sourceString;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Globalization;
|
||||
using System.Text.RegularExpressions;
|
||||
using Umbraco.Cms.Core.Models.PublishedContent;
|
||||
using Umbraco.Cms.Core.Routing;
|
||||
|
||||
namespace Umbraco.Cms.Core.Templates;
|
||||
@@ -45,17 +46,18 @@ public sealed class HtmlLocalLinkParser
|
||||
/// <summary>
|
||||
/// Parses the string looking for the {localLink} syntax and updates them to their correct links.
|
||||
/// </summary>
|
||||
/// <param name="text"></param>
|
||||
/// <param name="preview"></param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("This method overload is no longer used in Umbraco and delegates to the overload without the preview parameter. Scheduled for removal in Umbraco 18.")]
|
||||
public string EnsureInternalLinks(string text, bool preview) => EnsureInternalLinks(text);
|
||||
|
||||
/// <summary>
|
||||
/// Parses the string looking for the {localLink} syntax and updates them to their correct links.
|
||||
/// </summary>
|
||||
/// <param name="text"></param>
|
||||
/// <returns></returns>
|
||||
public string EnsureInternalLinks(string text)
|
||||
public string EnsureInternalLinks(string text) => EnsureInternalLinks(text, UrlMode.Default);
|
||||
|
||||
/// <summary>
|
||||
/// Parses the string looking for the {localLink} syntax and updates them to their correct links.
|
||||
/// </summary>
|
||||
public string EnsureInternalLinks(string text, UrlMode urlMode)
|
||||
{
|
||||
foreach (LocalLinkTag tagData in FindLocalLinkIds(text))
|
||||
{
|
||||
@@ -63,8 +65,8 @@ public sealed class HtmlLocalLinkParser
|
||||
{
|
||||
var newLink = tagData.Udi?.EntityType switch
|
||||
{
|
||||
Constants.UdiEntityType.Document => _publishedUrlProvider.GetUrl(tagData.Udi.Guid),
|
||||
Constants.UdiEntityType.Media => _publishedUrlProvider.GetMediaUrl(tagData.Udi.Guid),
|
||||
Constants.UdiEntityType.Document => _publishedUrlProvider.GetUrl(tagData.Udi.Guid, urlMode),
|
||||
Constants.UdiEntityType.Media => _publishedUrlProvider.GetMediaUrl(tagData.Udi.Guid, urlMode),
|
||||
_ => string.Empty,
|
||||
};
|
||||
|
||||
@@ -73,7 +75,7 @@ public sealed class HtmlLocalLinkParser
|
||||
}
|
||||
else if (tagData.IntId.HasValue)
|
||||
{
|
||||
var newLink = _publishedUrlProvider.GetUrl(tagData.IntId.Value);
|
||||
var newLink = _publishedUrlProvider.GetUrl(tagData.IntId.Value, urlMode);
|
||||
text = text.Replace(tagData.TagHref, newLink);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class MarkdownEditorValueConverter : PropertyValueConverterBase, IDeliver
|
||||
var sourceString = source.ToString()!;
|
||||
|
||||
// ensures string is parsed for {localLink} and URLs are resolved correctly
|
||||
sourceString = _localLinkParser.EnsureInternalLinks(sourceString, preview);
|
||||
sourceString = _localLinkParser.EnsureInternalLinks(sourceString);
|
||||
sourceString = _urlParser.EnsureUrls(sourceString);
|
||||
|
||||
return sourceString;
|
||||
|
||||
@@ -135,7 +135,7 @@ public class RteBlockRenderingValueConverter : SimpleRichTextValueConverter, IDe
|
||||
var sourceString = intermediateValue.Markup;
|
||||
|
||||
// ensures string is parsed for {localLink} and URLs and media are resolved correctly
|
||||
sourceString = _linkParser.EnsureInternalLinks(sourceString, preview);
|
||||
sourceString = _linkParser.EnsureInternalLinks(sourceString);
|
||||
sourceString = _urlParser.EnsureUrls(sourceString);
|
||||
sourceString = _imageSourceParser.EnsureImageSources(sourceString);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user