Merge pull request #17636 from abpframework/7.4-improve-widget-regex

Improve CmsKit Widget Parsing Regex
pull/17659/head
SALİH ÖZKARA 1 year ago committed by GitHub
commit a053006714
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -5,6 +5,8 @@ using Volo.Abp.Modularity;
using Volo.Abp.VirtualFileSystem; using Volo.Abp.VirtualFileSystem;
using Volo.CmsKit.Reactions; using Volo.CmsKit.Reactions;
using Volo.CmsKit.Web.Icons; using Volo.CmsKit.Web.Icons;
using Markdig;
using Microsoft.Extensions.DependencyInjection;
namespace Volo.CmsKit.Web; namespace Volo.CmsKit.Web;
@ -32,6 +34,14 @@ public class CmsKitCommonWebModule : AbpModule
options.ReactionIcons[StandardReactions.Victory] = new LocalizableIconDictionary("fas fa-hand-peace text-warning"); options.ReactionIcons[StandardReactions.Victory] = new LocalizableIconDictionary("fas fa-hand-peace text-warning");
options.ReactionIcons[StandardReactions.Rock] = new LocalizableIconDictionary("fas fa-hand-rock text-warning"); options.ReactionIcons[StandardReactions.Rock] = new LocalizableIconDictionary("fas fa-hand-rock text-warning");
}); });
context.Services
.AddSingleton(_ => new MarkdownPipelineBuilder()
.UseAutoLinks()
.UseBootstrap()
.UseGridTables()
.UsePipeTables()
.Build());
Configure<AbpVirtualFileSystemOptions>(options => Configure<AbpVirtualFileSystemOptions>(options =>
{ {

@ -40,7 +40,7 @@ public class ContentParser : ITransientDependency
protected virtual void ParseContent(string content, List<string> parsedList) protected virtual void ParseContent(string content, List<string> parsedList)
{ {
var replacedText = Regex.Replace(content, @"\[Widget.*?\]", Delimeter); var replacedText = Regex.Replace(content, @"\[Widget.*.Type=.*?\]", Delimeter);
if (!replacedText.Contains(Delimeter)) if (!replacedText.Contains(Delimeter))
{ {
parsedList.Add(replacedText); parsedList.Add(replacedText);
@ -78,7 +78,7 @@ public class ContentParser : ITransientDependency
{ {
content = Regex.Replace(content, @"=\s*""", @"="""); content = Regex.Replace(content, @"=\s*""", @"=""");
content = Regex.Replace(content, @"""\s*=", @"""="); content = Regex.Replace(content, @"""\s*=", @"""=");
var widgets = Regex.Matches(content, @"(?<=\[Widget)(.*?)(?=\])").Cast<Match>().Select(p => p.Value).ToList(); var widgets = Regex.Matches(content, @"(?<=\[Widget)(.*?)(?=\])").Select(p => p.Value).ToList();
for (int i = 0, k = 0; i < parsedList.Count; i++) for (int i = 0, k = 0; i < parsedList.Count; i++)
{ {
if (parsedList[i] == Delimeter) if (parsedList[i] == Delimeter)
@ -86,9 +86,9 @@ public class ContentParser : ITransientDependency
if (widgets.Count > k) if (widgets.Count > k)
{ {
var preparedContent = string.Join("", widgets[k]); var preparedContent = string.Join("", widgets[k]);
var keys = Regex.Matches(preparedContent, @"(?<=\s)(.*?)(?==\s*"")").Cast<Match>() var keys = Regex.Matches(preparedContent, @"(?<=\s)(.*?)(?==\s*"")")
.Select(p => p.Value).Where(p => p != string.Empty).ToList(); .Select(p => p.Value).Where(p => p != string.Empty).ToList();
var values = Regex.Matches(preparedContent, @"(?<=\s*[a-zA-Z]*=\s*"")(.*?)(?="")").Cast<Match>() var values = Regex.Matches(preparedContent, @"(?<=\s*[a-zA-Z]*=\s*"")(.*?)(?="")")
.Select(p => p.Value).ToList(); .Select(p => p.Value).ToList();
var widgetTypeIndex = keys.IndexOf("Type"); var widgetTypeIndex = keys.IndexOf("Type");
@ -98,7 +98,7 @@ public class ContentParser : ITransientDependency
var name = _options.WidgetConfigs.Where(p => p.Key == widgetType).Select(p => p.Value.Name).FirstOrDefault(); var name = _options.WidgetConfigs.Where(p => p.Key == widgetType).Select(p => p.Value.Name).FirstOrDefault();
if (name is not null && widgets.Count > k) if (name is not null && widgets.Count > k)
{ {
values[0] = name; values[widgetTypeIndex] = name;
var contentFragment = new ContentFragment() { Type = Widget }; var contentFragment = new ContentFragment() { Type = Widget };
contentFragments.Add(contentFragment); contentFragments.Add(contentFragment);
for (int kv = 0; kv < values.Count; kv++) for (int kv = 0; kv < values.Count; kv++)

@ -1,5 +1,4 @@
using Markdig; using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp; using Volo.Abp;
using Volo.Abp.AspNetCore.Mvc.Localization; using Volo.Abp.AspNetCore.Mvc.Localization;
@ -65,14 +64,6 @@ public class CmsKitPublicWebModule : AbpModule
options.AddMaps<CmsKitPublicWebModule>(validate: true); options.AddMaps<CmsKitPublicWebModule>(validate: true);
}); });
context.Services
.AddSingleton(_ => new MarkdownPipelineBuilder()
.UseAutoLinks()
.UseBootstrap()
.UseGridTables()
.UsePipeTables()
.Build());
Configure<DynamicJavaScriptProxyOptions>(options => Configure<DynamicJavaScriptProxyOptions>(options =>
{ {
options.DisableModule(CmsKitPublicRemoteServiceConsts.ModuleName); options.DisableModule(CmsKitPublicRemoteServiceConsts.ModuleName);

Loading…
Cancel
Save