private bool ProcessNextLine(IDOTNode node, out IDOTNode newnode, out bool backup) { var islast = false; var ismatch = false; // Check to see if we have an end match if (this.CheckForMatch(this.EndExpressions, node, out newnode)) { node.ProcessingType = DOTProcessingType.Remove; islast = true; } // If we don't have an end match but don't have any Line exressions we're still in the block else if ((this.LineExpressions.Count == 0 && this.EndExpressions.Count > 0)) { ismatch = true; newnode = new DOTNode() { BlockType = this.LineType, NodeType = DOTNodeType.Text, Text = node.Text }; } // if we have line expressions we check for a match. else { ismatch = this.CheckForMatch(this.LineExpressions, node, out newnode); } backup = (!islast) && (!ismatch); return(islast ? islast : !ismatch); }
private bool CheckForMatch(List <string> expressions, IDOTNode node, out IDOTNode newnode) { var ismatch = false; newnode = null; foreach (var expression in expressions) { var reg = new Regex(expression); if (reg.IsMatch(node.Text)) { ismatch = true; MatchCollection matches = reg.Matches(node.Text); var match = matches[0]; if (!string.IsNullOrEmpty(match.Groups[TextGroup].Value)) { newnode = new DOTNode() { BlockType = this.LineType, NodeType = DOTNodeType.Text, Text = match.Groups[TextGroup].Value }; } break; } } return(ismatch); }
private bool ProcessNextLine(IDOTNode node, out IDOTNode newnode) { var islast = true; newnode = null; foreach (var expression in this.Expressions) { if (Regex.IsMatch(node.Text, expression)) { islast = false; MatchCollection matches = Regex.Matches(node.Text, expression); var match = matches[0]; if (!string.IsNullOrEmpty(match.Groups[TextGroup].Value)) { newnode = new DOTNode() { BlockType = _linetype, NodeType = DOTNodeType.Text, Text = match.Groups[TextGroup].Value }; } break; } } return(islast); }
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); } } } }