diff --git a/TASVideos.WikiEngine/NodeImplementations.cs b/TASVideos.WikiEngine/NodeImplementations.cs index ad35d5a41..5e6a2d02b 100644 --- a/TASVideos.WikiEngine/NodeImplementations.cs +++ b/TASVideos.WikiEngine/NodeImplementations.cs @@ -464,8 +464,16 @@ public string InnerText(IWriterHelper h) // to the end user. TODO: __wikiLink really needs to be its own AST type. if (Name == "__wikiLink") { - Parameters.TryGetValue("displaytext", out var ret); - return ret ?? ""; + if (Parameters.TryGetValue("displaytext", out var displaytext)) + { + return displaytext; + } + else if (Parameters.TryGetValue("href", out var href)) + { + return href[1..]; + } + + return ""; } return ""; @@ -492,8 +500,9 @@ public IEnumerable CloneForToc() // See comment above if (Name == "__wikiLink") { - Parameters.TryGetValue("displaytext", out var content); - return new[] { new Text(CharStart, content ?? "") { CharEnd = CharEnd } }; + Parameters.TryGetValue("displaytext", out var displaytext); + Parameters.TryGetValue("href", out var href); + return new[] { new Text(CharStart, displaytext ?? href?[1..] ?? "") { CharEnd = CharEnd } }; } return Enumerable.Empty(); diff --git a/TASVideos/ViewComponents/WikiLink.cs b/TASVideos/ViewComponents/WikiLink.cs index 9729cc488..1535857bc 100644 --- a/TASVideos/ViewComponents/WikiLink.cs +++ b/TASVideos/ViewComponents/WikiLink.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Mvc; +using TASVideos.Core.Services.Wiki; using TASVideos.Data; using TASVideos.Data.Helpers; using TASVideos.WikiEngine; @@ -6,6 +7,7 @@ namespace TASVideos.ViewComponents; [WikiModule(WikiModules.WikiLink)] +[TextModule] public class WikiLink : ViewComponent { private readonly ApplicationDbContext _db; @@ -16,6 +18,17 @@ public WikiLink(ApplicationDbContext db) } public async Task InvokeAsync(string href, string? displayText) + { + return View(await InvokeInternal(href, displayText)); + } + + public async Task RenderTextAsync(IWikiPage? pageData, string href, string? displayText) + { + WikiLinkModel wikiLinkModel = await InvokeInternal(href, displayText); + return wikiLinkModel.DisplayText; + } + + private async Task InvokeInternal(string href, string? displayText) { int? id; string? titleText = null; @@ -63,12 +76,12 @@ public async Task InvokeAsync(string href, string? display displayText = href[1..]; } - return View(new WikiLinkModel + return new WikiLinkModel { Href = href, DisplayText = displayText, Title = titleText, - }); + }; } private async Task GetPublicationTitle(int id)