From c3eef7a06a9495d5d0c860911ea0e916faafbcd2 Mon Sep 17 00:00:00 2001 From: malik masis Date: Mon, 6 Jun 2022 18:34:40 +0300 Subject: [PATCH] Splitted MarkdownContentFragment still need development --- .../Shared/Components/Pages/ContentParser.cs | 51 ++++++++++++++----- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs index d9156e5a58..f91e6d22b7 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs @@ -1,5 +1,7 @@ +using System; using System.Collections.Generic; using System.Linq; +using System.Text.RegularExpressions; using System.Threading.Tasks; using Microsoft.Extensions.Options; using Volo.Abp.DependencyInjection; @@ -16,19 +18,44 @@ public class ContentParser : IContentParser, ITransientDependency public async Task> ParseAsync(string content) { + if (!_options.WidgetConfigs.Any()) + { + return new List() + { + new MarkdownContentFragment() { Content = content } + }; + } + + MatchCollection mc = Regex.Matches(content, @"(?<=\[Wid)(.*?)(?=\])");//(?<=X)(.*?)(?=Y) + + string split = "-----"; + + var polls = new List(); + foreach (Match m in mc) + { + polls.Add("[Wid" + m + "]"); + content = content.Replace("[Wid" + m + "]", split); + } + + var splittedContent = content.Split(split, StringSplitOptions.RemoveEmptyEntries); + + var contentFragments = new List(); var name = _options.WidgetConfigs.FirstOrDefault(p => p.Key == "Poll").Value?.Name; - return new List { - new MarkdownContentFragment { - Content = "**ABP Framework** is completely open source and developed in a community-driven manner." - }, - new WidgetContentFragment(name) { - Properties = { - { "name", "poll-name" } - } - }, - new MarkdownContentFragment { - Content = "Thanks _for_ *your* feedback." + for (int b = 0; b < splittedContent.Length; b++) + { + contentFragments.Add(new MarkdownContentFragment() { Content = splittedContent[b] }); + if (b != splittedContent.Length - 1) + { + contentFragments.Add(new WidgetContentFragment(name) + { + Properties = + { + { "name", "poll-name" } + } + }); } - }; + } + + return contentFragments; } } \ No newline at end of file