public string ConvertToHtml(string toParse) { ParseTree parseTree = Parser.Parse(toParse); if (parseTree.HasErrors()) { return($"{Parser.Context.Status} before processing \"{Parser.Context.CurrentToken}\" at {Parser.Context.Source}"); } MarkdownGrammar.BuildAst(LanguageData, parseTree); var x = parseTree.Root.AstNode as BaseAst; var visitor = new HtmlConcreteVisitor(new StringBuilder()); x.AcceptVisitor(visitor); return(visitor.CompiledHtml); }
public void VisitorComplingTest() { //arrange var toParse = File.ReadAllText(sampleMarkdownFilePath); ParseTree parseTree = _parser.Parse(toParse); _grammar.BuildAst(_langData, parseTree); var x = parseTree.Root.AstNode as BaseAst; var visitor = new HtmlConcreteVisitor(new StringBuilder()); //act x.AcceptVisitor(visitor); Console.WriteLine(visitor.CompiledHtml); //assert Assert.AreEqual(visitor.CompiledHtml, File.ReadAllText(@"..\..\..\compiledMarkDown.txt")); Assert.NotNull(parseTree); }