internal void ProcessRootMD(string md) { p = new MarkdownPipelineBuilder().UsePipeTables(new PipeTableOptions { RequireHeaderSeparator = true }) .UseBootstrap() .UseYamlFrontMatter() .UseGenericAttributes() .UseAutoIdentifiers(AutoIdentifierOptions.GitHub) .Build(); string name = Nav.SanitizeFilename(md); string html = raw_html; html = html.Replace("<!--REPLACE-SUPERNAV-->", MainNavHTML); string[] lines = File.ReadAllLines(md); StringBuilder raw = new StringBuilder(); foreach (string s in lines) { if (s.StartsWith("^")) { string include = $"{Nav.RootPath}\\source\\_includes\\{s.Replace("^", string.Empty)}.md"; if (File.Exists(include)) { raw.AppendLine(File.ReadAllText(include)); } } else { raw.AppendLine(ProcessLinks(s)); } } StringBuilder output = new StringBuilder(); //output.AppendLine("<div class=\"card\">"); //output.AppendLine("<div class=\"card-body\">"); output.AppendLine(Markdown.ToHtml(raw.ToString(), p)); //output.AppendLine("</div></div>"); html = html.Replace("%%TITLE%%", "Home"); html = html.Replace("<!--REPLACE--BODY-->", output.ToString()); try { File.WriteAllText(Nav.RootPath + dst + name + ".html", minifier.Minify(html).MinifiedContent); } catch (IOException) { Console.WriteLine("ERROR: " + Nav.RootPath + dst + name + ".html could not be written."); } //Console.Write("."); }
internal void Process() { navs = ParseDirectory(Nav.RootPath + src); p = new MarkdownPipelineBuilder().UsePipeTables(new PipeTableOptions { RequireHeaderSeparator = true }) .UseBootstrap() .UseYamlFrontMatter() .UseGenericAttributes() .UseAutoIdentifiers(AutoIdentifierOptions.GitHub) .Build(); for (int i = 0; i < MDs.Count; i++) { StringBuilder nhtml = new StringBuilder(); StringBuilder ohtml = new StringBuilder(); foreach (NavItem item in navs.Items) { ActiveState active = ActiveState.None; string uid = Nav.GetNavItem(MDs[i]).UID; string nid = Nav.SanitizeFilename(item.Title).Replace(" ", string.Empty); if (item.Items.Any(t => t.UID == uid)) { active = ActiveState.Child; nhtml.AppendLine("<li class=\"panel expanded active\">" + $"<a class=\"area\" href=\"#{nid}\" data-parent=\"#main-nav\" data-toggle=\"collapse\">{item.Title}</a>"); nhtml.AppendLine($"<ul id=\"{nid}\" class=\"collapse in\">"); } else { nhtml.AppendLine("<li class=\"panel collapsed\">" + $"<a class=\"area\" href=\"#{nid}\" data-parent=\"#main-nav\" data-toggle=\"collapse\">{item.Title}</a>"); nhtml.AppendLine($"<ul id=\"{nid}\" class=\"collapse\">"); } ohtml.AppendLine($"<optgroup label=\"{item.Title}\">"); foreach (NavItem navItem in item.Items) { if (active == ActiveState.Child && uid == navItem.UID) { nhtml.AppendLine(ProcessNav(navItem, active, uid)); ohtml.AppendLine($"<option selected=\"selected\" value=\"{navItem.Link}\">{navItem.Title}</option>"); } else { nhtml.AppendLine(ProcessNav(navItem, ActiveState.None, uid)); ohtml.AppendLine($"<option value=\"{navItem.Link}\">{navItem.Title}</option>"); } } nhtml.AppendLine("</ul></li></div>"); ohtml.AppendLine("</optgroup>"); } navHtml = minifier.Minify(nhtml.ToString()).MinifiedContent; optHtml = "<select id=\"small-nav-dropdown\">" + minifier.Minify(ohtml.ToString()).MinifiedContent + "</select>"; ProcessMD(MDs[i]); }//); //! Uncomment to use parallel processing. Useful when you have hundreds of files. // Parallel.For(0, MDs.Count, i => ProcessMD(MDs[i])); }
internal void ProcessMD(string md) { string name = Nav.SanitizeFilename(md); string html = raw_html; html = html.Replace("<!--REPLACE--OPT-->", optHtml); html = html.Replace("<!--REPLACE--NAV-->", navHtml); html = html.Replace("<!--REPLACE-SUPERNAV-->", MainNavHTML); #region Get Title string[] lines = File.ReadAllLines(md); if (lines.Length > 3) { for (int i = 1; i < 3; i++) { if (lines[i].Contains("title:")) { title = lines[i].Split(':')[1].Trim(); } } } if (string.IsNullOrEmpty(title.Trim())) { title = name.Replace("-", " "); } StringBuilder bread = new StringBuilder(); if (navs != null) { bread.AppendLine("<ol class=\"breadcrumb visible-md visible-lg\">"); bread.AppendLine( "<li class=\"breadcrumb-item\"><a href=\"/index.html\">Home</a></li>"); bread.AppendLine($"<li class=\"breadcrumb-item\"><a href=\"{BaseItem.Link}\">{BaseItem.Title}</a></li>"); if (navs.Items.Any(i => i.Items.Any(x => x.Title == title))) { bread.AppendLine( $"<li class=\"breadcrumb-item\">{navs.Items.First(i => i.Items.Any(x => x.Title == title))}</li>"); } bread.AppendLine($"<li class=\"breadcrumb-item active\">{title}</li>"); bread.AppendLine("</ol>"); } #endregion Get Title StringBuilder raw = new StringBuilder(); foreach (string s in lines.Skip(3)) { if (s.StartsWith("^")) { string include = $"{Nav.RootPath}\\source\\_includes\\{s.Replace("^", string.Empty)}.md"; if (File.Exists(include)) { raw.AppendLine(File.ReadAllText(include)); } } else { raw.AppendLine(ProcessLinks(s)); } } if (!md.ToLower().Contains("index.md")) { string doc = Markdown.ToPlainText(raw.ToString()); doc = Regex.Replace(doc.Substring(0, doc.Length >= 1200 ? 1200 : doc.Length), @"\{([^\}]+)\}", ""); doc = Regex.Replace(doc.Substring(0, doc.Length >= 1200 ? 1200 : doc.Length), @"\<([^\>]+)\>", ""); search.Add(new SearchObject { url = Nav.GetNavItem(md).Link, title = title, hive = BaseItem.Title, parent = navs.Items.Any(i => i.Items.Any(x => x.Title == title)) ? navs.Items.First(i => i.Items.Any(x => x.Title == title)).Title : "", text = doc }); } StringBuilder output = new StringBuilder(); output.AppendLine(Markdown.ToHtml(raw.ToString(), p)); if (ProcessProceduralFiles) { string @params = $"{Path.GetDirectoryName(md)}\\{Path.GetFileNameWithoutExtension(md)}.params.md"; //? PARAMETERS if (File.Exists(@params)) { output.AppendLine(ProcessParams(@params)); } } if (ProcessExampleFiles) { //! EXAMPLES output.AppendLine(ProcessExamples(md)); } if (ProcessTutorialFiles) { //! TUTORIALS output.AppendLine(ProcessTutorials(md)); } html = html.Replace("<!--REPLACE--BODY-->", $"{bread}<p class=\"faux-h1\">{title}</p>{output}"); html = html.Replace("%%TITLE%%", title); //html = html.Replace("<!--REPLACE--BREADCRUMBS-->", bread.ToString()); try { string subpath = Path.GetDirectoryName(md.Replace(Nav.RootPath, Nav.RootPath + dst)) .Replace("source\\", ""); if (subpath.Contains("Data")) { } if (!subpath.EndsWith("\\")) { subpath += "\\"; } subpath = Nav.ReplaceNumbers(subpath); Directory.CreateDirectory(subpath); //File.WriteAllText(subpath + name + ".html", html); File.WriteAllText(subpath + name + ".html", minifier.Minify(html).MinifiedContent); } catch (IOException) { Console.WriteLine("ERROR: " + Nav.RootPath + dst + name + ".html could not be written."); } //Console.Write("."); }