diff --git a/modules/docs/src/Volo.Docs.Web/HtmlConverting/DocumentSectionConsts.cs b/modules/docs/src/Volo.Docs.Web/HtmlConverting/DocumentSectionConsts.cs index ca3e8697e4..ba8d566563 100644 --- a/modules/docs/src/Volo.Docs.Web/HtmlConverting/DocumentSectionConsts.cs +++ b/modules/docs/src/Volo.Docs.Web/HtmlConverting/DocumentSectionConsts.cs @@ -4,6 +4,8 @@ { public const string SectionOpenerPrefix = "[doc-section:"; public const string SectionOpenerKeyValueSeparator = "="; + public const string SectionOpenerAndCondition = "&"; + public const string SectionOpenerOrCondition = "|"; public const string SectionOpenerPostfix = "]"; public const string SectionCloser = "[/doc-section]"; } diff --git a/modules/docs/src/Volo.Docs.Web/HtmlConverting/DocumentSectionFinder.cs b/modules/docs/src/Volo.Docs.Web/HtmlConverting/DocumentSectionFinder.cs index 5b1c1bfa1b..14ffbd7e61 100644 --- a/modules/docs/src/Volo.Docs.Web/HtmlConverting/DocumentSectionFinder.cs +++ b/modules/docs/src/Volo.Docs.Web/HtmlConverting/DocumentSectionFinder.cs @@ -30,7 +30,7 @@ namespace Volo.Docs.HtmlConverting } } - private DocumentSectionDictionary FindNextSections(string targetPartOfDocument, DocumentSectionDictionary sections) + private DocumentSectionDictionary FindNextSections(string targetPartOfDocument, DocumentSectionDictionary sections) { var startOfSection = targetPartOfDocument.IndexOf(DocumentSectionConsts.SectionOpenerPrefix, StringComparison.InvariantCulture); @@ -41,10 +41,44 @@ namespace Volo.Docs.HtmlConverting var endOfSectionOpener = targetPartOfDocument.Substring(startOfSection).IndexOf(DocumentSectionConsts.SectionOpenerPostfix, StringComparison.InvariantCulture); - var keyValueWithSeparator = targetPartOfDocument.Substring(startOfSection) + var keysValues = targetPartOfDocument.Substring(startOfSection) [DocumentSectionConsts.SectionOpenerPrefix.Length..endOfSectionOpener]; + sections = ParseAndAddContidionToSections(keysValues, sections); + + return FindNextSections(targetPartOfDocument.Substring(endOfSectionOpener), sections); + } + + private DocumentSectionDictionary ParseAndAddContidionToSections(string keysValues, DocumentSectionDictionary sections) + { + if (keysValues.Contains(DocumentSectionConsts.SectionOpenerAndCondition, StringComparison.InvariantCulture)) + { + var keysValuesSplitted = keysValues.Split(DocumentSectionConsts.SectionOpenerAndCondition); + foreach (var keyValue in keysValuesSplitted) + { + sections = AddContidionToSections(keyValue, sections); + } + } + else if (keysValues.Contains(DocumentSectionConsts.SectionOpenerOrCondition, StringComparison.InvariantCulture)) + { + var keysValuesSplitted = keysValues.Split(DocumentSectionConsts.SectionOpenerOrCondition); + foreach (var keyValue in keysValuesSplitted) + { + sections = AddContidionToSections(keyValue, sections); + } + } + else + { + sections = AddContidionToSections(keysValues, sections); + } + + return sections; + } + + private DocumentSectionDictionary AddContidionToSections(string keyValueWithSeparator, DocumentSectionDictionary sections) + { var keyValue = keyValueWithSeparator.Split(DocumentSectionConsts.SectionOpenerKeyValueSeparator); + var key = keyValue[0]; var value = keyValue[1]; @@ -57,7 +91,7 @@ namespace Volo.Docs.HtmlConverting sections.Add(key, new List() { value }); } - return FindNextSections(targetPartOfDocument.Substring(endOfSectionOpener), sections); + return sections; } } } diff --git a/modules/docs/src/Volo.Docs.Web/HtmlConverting/DocumentSectionHtmlReplacer.cs b/modules/docs/src/Volo.Docs.Web/HtmlConverting/DocumentSectionHtmlReplacer.cs index 55a7013d12..2e452d730a 100644 --- a/modules/docs/src/Volo.Docs.Web/HtmlConverting/DocumentSectionHtmlReplacer.cs +++ b/modules/docs/src/Volo.Docs.Web/HtmlConverting/DocumentSectionHtmlReplacer.cs @@ -1,17 +1,46 @@ -namespace Volo.Docs.HtmlConverting +using System; + +namespace Volo.Docs.HtmlConverting { public class DocumentSectionHtmlReplacer : IDocumentSectionHtmlReplacer { - public string Replace(string document, DocumentSectionDictionary sections) + public string Replace(string document) { - foreach (var key in sections) + while (document.Contains(DocumentSectionConsts.SectionOpenerPrefix)) { - foreach (var value in key.Value) + var sectionIndex = document.IndexOf(DocumentSectionConsts.SectionOpenerPrefix, StringComparison.InvariantCulture); + + var sectionCloserIndex = document.Substring(sectionIndex + DocumentSectionConsts.SectionOpenerPrefix.Length) + .IndexOf(DocumentSectionConsts.SectionOpenerPostfix, StringComparison.InvariantCulture); + + var keysValues = document.Substring(sectionIndex + DocumentSectionConsts.SectionOpenerPrefix.Length) + [0..sectionCloserIndex]; + + var andOperation = keysValues.Contains(DocumentSectionConsts.SectionOpenerAndCondition, StringComparison.InvariantCulture); + var orOperation = keysValues.Contains(DocumentSectionConsts.SectionOpenerOrCondition, StringComparison.InvariantCulture); + + var splitterChar = andOperation ? DocumentSectionConsts.SectionOpenerAndCondition : DocumentSectionConsts.SectionOpenerOrCondition; + + string[] keysValuesSplitted = keysValues.Split(splitterChar); + + var keys = new string[keysValuesSplitted.Length]; + var values = new string[keysValuesSplitted.Length]; + + for (int i = 0; i < keysValuesSplitted.Length; i++) { - document = document.Replace( - DocumentSectionConsts.SectionOpenerPrefix + key.Key + DocumentSectionConsts.SectionOpenerKeyValueSeparator + value + DocumentSectionConsts.SectionOpenerPostfix, - $"
"); + keys[i] = keysValuesSplitted[i].Split(DocumentSectionConsts.SectionOpenerKeyValueSeparator)[0]; + values[i] = keysValuesSplitted[i].Split(DocumentSectionConsts.SectionOpenerKeyValueSeparator)[1]; } + + var div = $"
"; + + document = document.Remove(sectionIndex, sectionCloserIndex + DocumentSectionConsts.SectionOpenerPrefix.Length +1); + + document = document.Insert(sectionIndex, div); } document = document.Replace(DocumentSectionConsts.SectionCloser, "
"); diff --git a/modules/docs/src/Volo.Docs.Web/HtmlConverting/HtmlNormalizer.cs b/modules/docs/src/Volo.Docs.Web/HtmlConverting/HtmlNormalizer.cs index ed3f999614..6f0a680ce2 100644 --- a/modules/docs/src/Volo.Docs.Web/HtmlConverting/HtmlNormalizer.cs +++ b/modules/docs/src/Volo.Docs.Web/HtmlConverting/HtmlNormalizer.cs @@ -28,7 +28,6 @@ namespace Volo.Docs.HtmlConverting }, RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.Multiline); - return content; } @@ -36,6 +35,5 @@ namespace Volo.Docs.HtmlConverting { return Regex.Replace(content, "", "", RegexOptions.IgnoreCase); } - } } \ No newline at end of file diff --git a/modules/docs/src/Volo.Docs.Web/HtmlConverting/IDocumentSectionHtmlReplacer.cs b/modules/docs/src/Volo.Docs.Web/HtmlConverting/IDocumentSectionHtmlReplacer.cs index 7f517bc341..509bee0798 100644 --- a/modules/docs/src/Volo.Docs.Web/HtmlConverting/IDocumentSectionHtmlReplacer.cs +++ b/modules/docs/src/Volo.Docs.Web/HtmlConverting/IDocumentSectionHtmlReplacer.cs @@ -4,6 +4,6 @@ namespace Volo.Docs.HtmlConverting { public interface IDocumentSectionHtmlReplacer : ITransientDependency { - public string Replace(string document, DocumentSectionDictionary sections); + public string Replace(string document); } } diff --git a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs index c06f24f7fa..083f045227 100644 --- a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs +++ b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs @@ -384,7 +384,7 @@ namespace Volo.Docs.Pages.Documents.Project { DocumentSections = _documentSectionFinder.Find(Document.Content); - Document.Content = _documentSectionHtmlReplacer.Replace(Document.Content, DocumentSections); + Document.Content = _documentSectionHtmlReplacer.Replace(Document.Content); var converter = _documentToHtmlConverterFactory.Create(Document.Format ?? Project.Format); var content = converter.Convert(Project, Document, GetSpecificVersionOrLatest(), LanguageCode); diff --git a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/index.js b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/index.js index 6b27b20a7f..6343e6bc83 100644 --- a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/index.js +++ b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/index.js @@ -102,7 +102,6 @@ ); }; - var initSections = function () { var getQueryStringParameterByName = function (name) { var url = window.location.href; @@ -139,20 +138,73 @@ window.history.replaceState({}, document.title, new_uri); }; - var changeSections = function (combobox) { - var key = $(combobox).data('key'); - var value = combobox.value; + var setSections = function () { + + var sections = $(".doc-section"); + + var comboboxes = $(".doc-section-combobox"); + var comboboxKeys = []; + var comboboxSelectedValues = []; + + for (var i = 0; i < comboboxes.length; i++) { + comboboxKeys.push($(comboboxes[i]).data("key")); + comboboxSelectedValues.push(comboboxes[i].value); + } + + for (i = 0; i < sections.length; i++) { + var keys = $(sections[i]).data("keys"); + var values = $(sections[i]).data("values"); + + var show = false; + var keysSplitted; + var valuesSplitted; + + if (keys.indexOf("&") >= 0) { + keysSplitted = keys.split("&"); + valuesSplitted = values.split("&"); + + var hide = false; - $(".doc-section[data-key=" + key + "]").hide(); - $(".doc-section[data-key=" + key + "][data-value=" + value + "]").show(); + for (var k = 0; k < keysSplitted.length; k++) { + if (valuesSplitted[k] !== comboboxSelectedValues[comboboxKeys.indexOf(keysSplitted[k])]) { + hide = true; + break; + } + } - localStorage["abp-doc-section-" + key] = value; + show = !hide; + } + else if (keys.indexOf("|") >= 0) { + keysSplitted = keys.split("|"); + valuesSplitted = values.split("|"); + + for (k = 0; k < keysSplitted.length; k++) { + if (valuesSplitted[k] === comboboxSelectedValues[comboboxKeys.indexOf(keysSplitted[k])]) { + show = true; + break; + } + } + } + else { + if (values === comboboxSelectedValues[comboboxKeys.indexOf(keys)]) { + show = true; + } + } + + if (show) { + $(sections[i]).show(); + } + else { + $(sections[i]).hide(); + } + } setQueryString(); }; $(".doc-section-combobox").change(function () { - changeSections(this); + localStorage["abp-doc-section-" + $(this).data("key")] = this.value; + setSections(); }); var comboboxes = $(".doc-section-combobox"); @@ -172,9 +224,7 @@ } } - for (var k = 0; k < comboboxes.length; k++) { - changeSections(comboboxes[k]); - } + setSections(); };