private static void LoadMarkdownPageProperties(SidenavFile file) { List <PProperty> properties = new List <PProperty>(); string fullContent = Utils.GetFullFileConent(file.InputFilePath); string[] lines = fullContent.Split(Configuration.NewlineChars, StringSplitOptions.None); if (lines.Length == 0) { file.SetContent(properties, string.Empty); return; } int lineNum = 0; Regex regex = new Regex("Property:*,*"); while (regex.IsMatch(lines[lineNum]) && lineNum < lines.Length) { string data = lines[lineNum].Substring(9); string[] datas = data.Split(','); string propertyName = datas[0].Trim(); string propertyValue = datas[1].Trim(); if (!string.IsNullOrEmpty(propertyName) && !string.IsNullOrEmpty(propertyValue)) { PProperty property = new PProperty(propertyName, propertyValue); properties.Add(property); } lineNum++; } StringBuilder builder = new StringBuilder(); bool first = true; for (int i = lineNum; i < lines.Length; i++) { if (!first) { builder.Append(Configuration.DefaultNewlineChar); } builder.Append(lines[i]); first = false; } var pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build(); var markdown = Markdown.ToHtml(builder.ToString(), pipeline); file.SetContent(properties, markdown); }
private static void LoadHtmlPageProperties(SidenavFile file) { List <PProperty> properties = new List <PProperty>(); string fullContent = Utils.GetFullFileConent(file.InputFilePath); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(fullContent); doc.RemoveComments(); HtmlNode[] propertyNodes = doc.DocumentNode.Descendants("PProperty").ToArray(); foreach (HtmlNode node in propertyNodes) { string propertyName = HttpUtility.UrlEncode(node.GetAttributeValue("name", string.Empty)); string propertyValue = node.GetAttributeValue("value", string.Empty); if (!string.IsNullOrEmpty(propertyName)) { PProperty property = new PProperty(propertyName, propertyValue); properties.Add(property); } node.Remove(); } file.SetContent(properties, doc.DocumentNode.OuterHtml); }