Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement text for wikiLink module #1768

Merged
merged 1 commit into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions TASVideos.WikiEngine/NodeImplementations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
Expand All @@ -492,8 +500,9 @@ public IEnumerable<INode> 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<INode>();
Expand Down
17 changes: 15 additions & 2 deletions TASVideos/ViewComponents/WikiLink.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using Microsoft.AspNetCore.Mvc;
using TASVideos.Core.Services.Wiki;
using TASVideos.Data;
using TASVideos.Data.Helpers;
using TASVideos.WikiEngine;

namespace TASVideos.ViewComponents;

[WikiModule(WikiModules.WikiLink)]
[TextModule]
public class WikiLink : ViewComponent
{
private readonly ApplicationDbContext _db;
Expand All @@ -16,6 +18,17 @@ public WikiLink(ApplicationDbContext db)
}

public async Task<IViewComponentResult> InvokeAsync(string href, string? displayText)
{
return View(await InvokeInternal(href, displayText));
}

public async Task<string> RenderTextAsync(IWikiPage? pageData, string href, string? displayText)
{
WikiLinkModel wikiLinkModel = await InvokeInternal(href, displayText);
return wikiLinkModel.DisplayText;
}

private async Task<WikiLinkModel> InvokeInternal(string href, string? displayText)
{
int? id;
string? titleText = null;
Expand Down Expand Up @@ -63,12 +76,12 @@ public async Task<IViewComponentResult> InvokeAsync(string href, string? display
displayText = href[1..];
}

return View(new WikiLinkModel
return new WikiLinkModel
{
Href = href,
DisplayText = displayText,
Title = titleText,
});
};
}

private async Task<string?> GetPublicationTitle(int id)
Expand Down
Loading