public virtual bool Process(DocumentObjectTree Dot) { PreProcess(Dot); ReProcess(Dot); CleanUp(Dot); return(true); }
public bool Process(DocumentObjectTree Dot) { foreach (var node in Dot.RootNode.Nodes) { { ProcessNode(node.Value); } } return(true); }
/// <summary> /// Processes the Raw DocumentObject line by line /// </summary> /// <param name="Dot"></param> /// <returns></returns> public bool Process(DocumentObjectTree Dot) { if (Dot != null && Dot.RootNode != null) { var index = 1; while (index <= Dot.RootNode.Nodes.Count) { var node = Dot.RootNode.Nodes[index]; // only process raw nodes if (node.NodeType == DOTNodeType.Raw) { foreach (var proc in PreProcessors) { var ismatch = false; MatchCollection matches = null; foreach (var expression in proc.Value.Expressions) { var reg = new Regex(expression, RegexOptions.ECMAScript); if (reg.IsMatch(node.Text)) { matches = reg.Matches(node.Text); ismatch = true; break; } } if (ismatch) { proc.Value.Process(Dot.RootNode, matches, ref index); break; } } } index++; } } this.CleanUp(Dot); return(true); }
public string Convert(DocumentObjectTree dot, bool fullHtml = false) { var html = string.Empty; this.Dot = dot; this.FullHtml = fullHtml; this.IndexTree(dot.RootNode); if (Dot.RootNode != null) { html = this.AddSubNodes(Dot.RootNode); } if (fullHtml) { return(HtmlWrapper(html)); } else { return(html.ToString()); } }
protected void CleanUp(DocumentObjectTree Dot) { var list = Dot.RootNode.Nodes.Where(item => item.Value.ProcessingType == DOTProcessingType.Remove).ToList(); list.ForEach(item => Dot.RootNode.DeleteNode(item.Key)); }
protected virtual void ReProcess(DocumentObjectTree Dot) { }
static void Main(string[] args) { Console.WriteLine("Markdown to HTML Coverter"); string workingdir = $"{Directory.GetCurrentDirectory()}\\MD"; // string workingdir = @"C:\Users\Shaun.Obsidian\source\repos\MD-To-HTML-Converter\MD"; //// Get the directory //var value = string.Empty; //Console.Write(string.Concat("Directory to process? (default=", workingdir, ")")); //value = Console.ReadLine(); //workingdir = string.IsNullOrEmpty(value) ? workingdir : value; //// Get the directory //value = string.Empty; //Console.Write(string.Concat("Show Debug Information? (default=", "Y", ")")); //value = Console.ReadLine(); //var debug = value.ToUpper() == "Y"; var debug = true; // Loop through each MD files in the directory foreach (var file in Directory.GetFiles(workingdir, "*.md")) { Dot = new DocumentObjectTree() { FileName = file }; Dot.RootNode = new DOTNode() { NodeType = DOTNodeType.RootNode }; Console.WriteLine($"Reading File: {file}"); var lines = File.ReadAllLines(file); foreach (var line in lines) { var dot = new DOTNode() { NodeType = DOTNodeType.Raw, Text = line }; Dot.RootNode.AddNode(dot); } Console.WriteLine("Building Document Object Tree"); if (debug) { OutputTree(); } InputProcessor.Process(Dot); if (debug) { Dot.ToConsole(); } Console.WriteLine("Running Converters"); foreach (var converter in Converters) { var outputfilename = file.Replace("md", "html"); var html = HTMLConverter.RunConvert(Dot, true); Console.WriteLine($"Writing Output File: {outputfilename}"); File.WriteAllText(outputfilename, html); if (debug) { Console.WriteLine(html); } } } }
public static string RunConvert(DocumentObjectTree Dot, bool fullHtml = false) { var converter = new HTMLConverter(); return(converter.Convert(Dot, fullHtml)); }