public void TestDfmTagValidate() { var builder = new DfmEngineBuilder(new Options() { Mangle = false }); var mrb = new MarkdownValidatorBuilder( new ContainerConfiguration() .WithAssembly(typeof(DocfxFlavoredMarkdownTest).Assembly) .CreateContainer()); mrb.AddTagValidators( new MarkdownTagValidationRule { TagNames = new List <string> { "em", "div" }, MessageFormatter = "Invalid tag({0})!", Behavior = TagValidationBehavior.Error, OpeningTagOnly = true, }, new MarkdownTagValidationRule { TagNames = new List <string> { "h1" }, MessageFormatter = "Warning tag({0})!", Behavior = TagValidationBehavior.Warning, }); mrb.AddValidators(HtmlMarkdownTokenValidatorProvider.ContractName); builder.Rewriter = mrb.Create(); var engine = builder.CreateDfmEngine(new DfmRenderer()); var listener = new TestLoggerListener("test!!!!" + "." + MarkdownValidatorBuilder.MarkdownValidatePhaseName); Logger.RegisterListener(listener); string result; using (new LoggerPhaseScope("test!!!!")) { result = engine.Markup(@"<div><i>x</i><EM>y</EM><h1>z</h1></div>", "test"); } Logger.UnregisterListener(listener); Assert.Equal("<div><i>x</i><EM>y</EM><h1>z</h1></div>", result); Assert.Equal(5, listener.Items.Count); Assert.Equal(new[] { HtmlMarkdownTokenValidatorProvider.WarningMessage, "Invalid tag(div)!", "Invalid tag(EM)!", "Warning tag(h1)!", "Warning tag(h1)!" }, from item in listener.Items select item.Message); }
public void TestDfmTagValidate() { var builder = new DfmEngineBuilder(new MarkdownLite.Options() { Mangle = false }); var mrb = new MarkdownRewriterBuilder(null); mrb.AddValidators( new MarkdownTagValidationRule { TagNames = new List <string> { "em", "div" }, MessageFormatter = "Invalid tag({0})!", Behavior = TagRewriteBehavior.Error, OpeningTagOnly = true, }, new MarkdownTagValidationRule { TagNames = new List <string> { "h1" }, MessageFormatter = "Invalid tag({0}), Removed!", Behavior = TagRewriteBehavior.ErrorAndRemove, }); builder.Rewriter = mrb.Create(); var engine = builder.CreateDfmEngine(new DfmRenderer()); var listener = new TestLoggerListener("test!!!!"); Logger.RegisterListener(listener); string result; using (new LoggerPhaseScope("test!!!!")) { result = engine.Markup(@"<div><i>x</i><EM>y</EM><h1>z</h1></div>", "test"); } Logger.UnregisterListener(listener); Assert.Equal("<div><i>x</i><EM>y</EM>z</div>", result); Assert.Equal(4, listener.Items.Count); Assert.Equal(new[] { "Invalid tag(div)!", "Invalid tag(EM)!", "Invalid tag(h1), Removed!", "Invalid tag(h1), Removed!" }, from item in listener.Items select item.Message); }
public void TestDfmTagValidate() { var builder = new DfmEngineBuilder(new MarkdownLite.Options() { Mangle = false }); var mrb = new MarkdownRewriterBuilder(null); mrb.AddValidators( new MarkdownTagValidationRule { TagNames = new List<string> { "em", "div" }, MessageFormatter = "Invalid tag({0})!", Behavior = TagRewriteBehavior.Error, OpeningTagOnly = true, }, new MarkdownTagValidationRule { TagNames = new List<string> { "h1" }, MessageFormatter = "Invalid tag({0}), Removed!", Behavior = TagRewriteBehavior.ErrorAndRemove, }); builder.Rewriter = mrb.Create(); var engine = builder.CreateEngine(new DfmRenderer()); var listener = new TestLoggerListener("test!!!!"); Logger.RegisterListener(listener); string result; using (new LoggerPhaseScope("test!!!!")) { result = engine.Markup(@"<div><i>x</i><EM>y</EM><h1>z</h1></div>", "test"); } Logger.UnregisterListener(listener); Assert.Equal("<div><i>x</i><EM>y</EM>z</div>", result); Assert.Equal(4, listener.Items.Count); Assert.Equal(new[] { "Invalid tag(div)!", "Invalid tag(EM)!", "Invalid tag(h1), Removed!", "Invalid tag(h1), Removed!" }, from item in listener.Items select item.Message); }
private void CleanUp() { Logger.UnregisterListener(Listener); Listener = null; }
private void Init(string phaseName) { Listener = new TestLoggerListener(phaseName); Logger.RegisterListener(Listener); }
private void CleanUp() { Logger.UnregisterAllListeners(); Listener = null; DocfxFlavoredMarked.ClearBuilder(); }
private void Init(string phaseName) { Listener = new TestLoggerListener(phaseName); Logger.RegisterListener(Listener); DocfxFlavoredMarked.ClearBuilder(); }
public void TestDfmTagValidate() { var builder = new DfmEngineBuilder(new Options() { Mangle = false }); var mrb = new MarkdownValidatorBuilder( new ContainerConfiguration() .WithAssembly(typeof(DocfxFlavoredMarkdownTest).Assembly) .CreateContainer()); mrb.AddTagValidators( new MarkdownTagValidationRule { TagNames = new List<string> { "em", "div" }, MessageFormatter = "Invalid tag({0})!", Behavior = TagValidationBehavior.Error, OpeningTagOnly = true, }, new MarkdownTagValidationRule { TagNames = new List<string> { "h1" }, MessageFormatter = "Warning tag({0})!", Behavior = TagValidationBehavior.Warning, }); mrb.AddValidators(HtmlMarkdownTokenValidatorProvider.ContractName); builder.Rewriter = mrb.Create(); var engine = builder.CreateDfmEngine(new DfmRenderer()); var listener = new TestLoggerListener("test!!!!" + "." + MarkdownValidatorBuilder.MarkdownValidatePhaseName); Logger.RegisterListener(listener); string result; using (new LoggerPhaseScope("test!!!!")) { result = engine.Markup(@"<div><i>x</i><EM>y</EM><h1>z</h1></div>", "test"); } Logger.UnregisterListener(listener); Assert.Equal("<div><i>x</i><EM>y</EM><h1>z</h1></div>", result); Assert.Equal(5, listener.Items.Count); Assert.Equal(new[] { HtmlMarkdownTokenValidatorProvider.WarningMessage, "Invalid tag(div)!", "Invalid tag(EM)!", "Warning tag(h1)!", "Warning tag(h1)!" }, from item in listener.Items select item.Message); }