public static string PreCompile(string HTMLContent, WidgetArgument Setting) { var ArgumentMatches = Regex.Matches(HTMLContent, @"\((<(?:[\S\s](?!\(<.+>\)))*?>)\)", RegexOptions.Singleline); while (ArgumentMatches.Count > 0) { foreach (Match match in ArgumentMatches) { HtmlDocument htmlArg = new HtmlDocument(); htmlArg.LoadHtml(match.Groups[1].Value); try { htmlArg.DocumentNode.SelectNodes("//text()[not(normalize-space())]").ToList().ForEach(element => element.Remove()); } catch { } HTMLContent = HTMLContent.Replace(match.Groups[1].Value, CompileNode(htmlArg.DocumentNode.FirstChild, 1, false)); //HTMLContent = HTMLContent.Replace(match.Groups[0].Value, CompileNode(htmlArg.DocumentNode.FirstChild, 1, false)); } ArgumentMatches = Regex.Matches(HTMLContent, @"\((<(?:[\S\s](?!\(<.+>\)))*?>)\)", RegexOptions.Singleline); } return(HTMLContent); }
public static string CompileFile(string FileAddress, string Destinationfolder) { HtmlDocument htmlDoc = new HtmlDocument(); WidgetArgument Setting = new WidgetArgument(); string JsFilePath = ""; string HtmlContent = ""; try{ HtmlContent = File.ReadAllText(FileAddress); } catch (Exception ex) { _ = ex; } string Output = ModelRefrences(); if (FileAddress.EndsWith(".html")) { JsFilePath = Path.Combine(Destinationfolder, Path.GetFileName(FileAddress)).Replace(".html", ".js"); } else if (FileAddress.EndsWith(".js")) { JsFilePath = Path.Combine(Destinationfolder, Path.GetFileName(FileAddress)); HtmlContent = Output + Setting.ImplementArguments(PreCompile(HtmlContent, Setting)); if (!string.IsNullOrEmpty(Destinationfolder)) { File.WriteAllText(JsFilePath, HtmlContent); return(""); } else { return(HtmlContent); } } else { Console.WriteLine("Extension not recognized."); Console.WriteLine("Extensions can either be .html or .js"); return(""); }