Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
 private void CleanUp()
 {
     Logger.UnregisterListener(Listener);
     Listener = null;
 }
Пример #5
0
 private void Init(string phaseName)
 {
     Listener = new TestLoggerListener(phaseName);
     Logger.RegisterListener(Listener);
 }
Пример #6
0
 private void CleanUp()
 {
     Logger.UnregisterAllListeners();
     Listener = null;
     DocfxFlavoredMarked.ClearBuilder();
 }
Пример #7
0
 private void Init(string phaseName)
 {
     Listener = new TestLoggerListener(phaseName);
     Logger.RegisterListener(Listener);
     DocfxFlavoredMarked.ClearBuilder();
 }
Пример #8
0
 private void CleanUp()
 {
     Logger.UnregisterListener(Listener);
     Listener = null;
 }
Пример #9
0
 private void Init(string phaseName)
 {
     Listener = new TestLoggerListener(phaseName);
     Logger.RegisterListener(Listener);
 }
Пример #10
0
 private void CleanUp()
 {
     Logger.UnregisterAllListeners();
     Listener = null;
     DocfxFlavoredMarked.ClearBuilder();
 }
Пример #11
0
 private void Init(string phaseName)
 {
     Listener = new TestLoggerListener(phaseName);
     Logger.RegisterListener(Listener);
     DocfxFlavoredMarked.ClearBuilder();
 }
Пример #12
0
        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);
        }