diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/en.json b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/en.json index fc7a1884ef..bb34fc3d29 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/en.json +++ b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/en.json @@ -158,6 +158,7 @@ "YourEmailAddress": "Your e-mail address", "YourFullName": "Your full name", "YourMessage": "Your Message", - "YourReply": "Your reply" + "YourReply": "Your reply", + "MarkdownSupported": "Markdown supported." } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/CommentingViewComponent.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/CommentingViewComponent.cs index 411b088682..873b7daf07 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/CommentingViewComponent.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/CommentingViewComponent.cs @@ -8,6 +8,7 @@ using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc.UI; using Volo.Abp.AspNetCore.Mvc.UI.Widgets; using Volo.CmsKit.Public.Comments; +using Volo.CmsKit.Public.Web.Renderers; namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Commenting; @@ -21,13 +22,16 @@ namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Commenting; public class CommentingViewComponent : AbpViewComponent { public ICommentPublicAppService CommentPublicAppService { get; } + public IMarkdownToHtmlRenderer MarkdownToHtmlRenderer { get; } public AbpMvcUiOptions AbpMvcUiOptions { get; } public CommentingViewComponent( ICommentPublicAppService commentPublicAppService, - IOptions options) + IOptions options, + IMarkdownToHtmlRenderer markdownToHtmlRenderer) { CommentPublicAppService = commentPublicAppService; + MarkdownToHtmlRenderer = markdownToHtmlRenderer; AbpMvcUiOptions = options.Value; } @@ -35,8 +39,9 @@ public class CommentingViewComponent : AbpViewComponent string entityType, string entityId) { - var result = await CommentPublicAppService - .GetListAsync(entityType, entityId); + var comments = (await CommentPublicAppService + .GetListAsync(entityType, entityId)).Items; + var loginUrl = $"{AbpMvcUiOptions.LoginUrl}?returnUrl={HttpContext.Request.Path.ToString()}&returnUrlHash=#cms-comment_{entityType}_{entityId}"; @@ -45,12 +50,31 @@ public class CommentingViewComponent : AbpViewComponent EntityId = entityId, EntityType = entityType, LoginUrl = loginUrl, - Comments = result.Items.OrderByDescending(i => i.CreationTime).ToList() + Comments = comments.OrderByDescending(i => i.CreationTime).ToList() }; + await ConvertMarkdownTextsToHtml(viewModel); + return View("~/Pages/CmsKit/Shared/Components/Commenting/Default.cshtml", viewModel); } + private async Task ConvertMarkdownTextsToHtml(CommentingViewModel viewModel) + { + viewModel.RawCommentTexts = new Dictionary(); + + foreach (var comment in viewModel.Comments) + { + viewModel.RawCommentTexts.Add(comment.Id, comment.Text); + comment.Text = await MarkdownToHtmlRenderer.RenderAsync(comment.Text); + + foreach (var reply in comment.Replies) + { + viewModel.RawCommentTexts.Add(reply.Id, reply.Text); + reply.Text = await MarkdownToHtmlRenderer.RenderAsync(reply.Text); + } + } + } + public class CommentingViewModel { public string EntityType { get; set; } @@ -59,6 +83,9 @@ public class CommentingViewComponent : AbpViewComponent public string LoginUrl { get; set; } - public IReadOnlyList Comments { get; set; } + public List Comments { get; set; } + + public Dictionary RawCommentTexts { get; set; } } } + diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/Default.cshtml b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/Default.cshtml index ab4bd69b91..9d0438098d 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/Default.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/Default.cshtml @@ -49,6 +49,9 @@ } +
+ @L["MarkdownSupported"] +
; @@ -57,16 +60,7 @@ Func GetCommentContentArea(Guid id, string text) => @

- @{ - var lines = text.SplitToLines(); - if (lines.Any()) - { - foreach (var line in lines) - { - @line
- } - } - } + @Html.Raw(text)

; } @@ -114,9 +108,11 @@
@L["Update"] @L["Cancel"] -
+
+ @L["MarkdownSupported"] +
@@ -161,7 +157,7 @@ - @GetEditArea(comment.Id, comment.Text, comment.ConcurrencyStamp).Invoke(null) + @GetEditArea(comment.Id, Model.RawCommentTexts[comment.Id], comment.ConcurrencyStamp).Invoke(null) @if (comment.Replies.Any()) { @@ -191,7 +187,7 @@ - @GetEditArea(reply.Id, reply.Text, reply.ConcurrencyStamp).Invoke(null) + @GetEditArea(reply.Id, Model.RawCommentTexts[reply.Id], reply.ConcurrencyStamp).Invoke(null) } @@ -220,4 +216,3 @@ } - \ No newline at end of file