private static void UpdateVisibiltyByKeywordFilter(this AwesomeResourceGroup group, string[] keywords) { group.Visible = group.SelectionState != SelectionState.Unselected; if (group.Visible) { foreach (var resource in group.Resources) { resource.Visible = keywords.All(keyword => resource.Title.ToLower().Contains(keyword) || resource.DescriptionText.ToLower().Contains(keyword)); } group.SubGroups.UpdateVisibiltyByKeywordFilter(keywords); group.Visible = (group.ParagraphsHtml != "" && !keywords.Any()) || group.Resources.Any(r => r.Visible) || group.SubGroups.Any(g => g.Visible); } }
public static AwesomeResourceGroup ParseMarkdown(string markdownContents, AwesomeBlazorParserOptions options = null) { options ??= new AwesomeBlazorParserOptions(); var currentGroup = default(AwesomeResourceGroup); var awsomeBlazorRoot = new AwesomeResourceGroup(); var groups = new[] { awsomeBlazorRoot, null, null }; var paragraphs = new List <string>(); var prevLineType = LineTypes.Group; var lines = markdownContents.Split('\r', '\n'); foreach (var current in lines) { var groupMatch = Regex.Match(current, "^(?<level>#+)[ ]*(?<title>.+)$"); if (groupMatch.Success) { prevLineType = LineTypes.Group; var title = groupMatch.Groups["title"].Value; var level = Math.Max(1, groupMatch.Groups["level"].Value.Length - 1); if (title == options.EndCategoryName) { break; } if (currentGroup != null && paragraphs.Any(p => !string.IsNullOrEmpty(p))) { currentGroup.ParagraphsHtml = PostProcessHtml(Markdown.ToHtml(string.Join("\n", paragraphs)), stripParagraphTag: false); } paragraphs.Clear(); if (options.SkipCategoryNames.Contains(title)) { currentGroup = null; } else { var titleHtml = PostProcessHtml(Markdown.ToHtml(title), stripParagraphTag: true); currentGroup = new AwesomeResourceGroup(title: HtmlToText(titleHtml), titleHtml: titleHtml); groups[level - 1].SubGroups.Add(currentGroup); groups[level] = currentGroup; } } else if (currentGroup != null) { if (TryParseAsResource(current, out var resource)) { prevLineType = LineTypes.Resource; currentGroup.Resources.Add(resource); } else if (prevLineType == LineTypes.Resource && !string.IsNullOrEmpty(current)) { prevLineType = LineTypes.Resource; var descriptionHtml = PostProcessHtml(Markdown.ToHtml(current), stripParagraphTag: true); var descriptionText = HtmlToText(descriptionHtml); var lastResource = currentGroup.Resources.Last(); lastResource.DescriptionHtml += " " + descriptionHtml; lastResource.DescriptionText += " " + descriptionText; } else { prevLineType = LineTypes.Paragraph; paragraphs.Add(current); } } } return(awsomeBlazorRoot); }