상속: Microsoft.DocAsCode.MarkdownLite.GfmEngineBuilder
예제 #1
0
 public DfmService(string baseDir, string templateDir, ImmutableDictionary<string, string> tokens, IMarkdownTokenTreeValidator tokenTreeValidator, IReadOnlyList<string> fallbackFolders = null)
 {
     var options = DocfxFlavoredMarked.CreateDefaultOptions();
     options.ShouldExportSourceInfo = true;
     _builder = DocfxFlavoredMarked.CreateBuilder(baseDir, templateDir, options, fallbackFolders);
     _builder.TokenTreeValidator = tokenTreeValidator;
     _tokens = tokens;
 }
예제 #2
0
            public DfmService(string baseDir, string templateDir, ImmutableDictionary<string, string> tokens, IEnumerable<IMarkdownTokenTreeValidator> tokenTreeValidator, IReadOnlyList<string> fallbackFolders = null)
            {
                var options = DocfxFlavoredMarked.CreateDefaultOptions();
                options.ShouldExportSourceInfo = true;
                _builder = DocfxFlavoredMarked.CreateBuilder(baseDir, templateDir, options, fallbackFolders);
                _builder.TokenTreeValidator = MarkdownTokenTreeValidatorFactory.Combine(tokenTreeValidator);
                _tokens = tokens;

                _incrementalContextHash = ComputeIncrementalContextHash(baseDir, templateDir, tokenTreeValidator);
            }
 public DfmJsonTokenTreeService(string baseDir, ImmutableDictionary<string, string> tokens, IMarkdownTokenTreeValidator tokenTreeValidator)
 {
     _builder = DocfxFlavoredMarked.CreateBuilder(baseDir);
     _builder.TokenTreeValidator = tokenTreeValidator;
     _tokens = tokens;
 }
예제 #4
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[]
            {
                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,
                },
                new MarkdownTagValidationRule
                {
                    TagNames = new List<string> { "script" },
                    MessageFormatter = "Warning tag({0})!",
                    Behavior = TagValidationBehavior.Warning,
                },
                new MarkdownTagValidationRule
                {
                    TagNames = new List<string> { "pre" },
                    MessageFormatter = "Warning tag({0})!",
                    Behavior = TagValidationBehavior.Warning,
                },
            });
            mrb.AddValidators(new[]
            {
                new MarkdownValidationRule
                {
                    ContractName =  HtmlMarkdownTokenValidatorProvider.ContractName,
                }
            });
            builder.Rewriter = mrb.CreateRewriter();

            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<pre><code>a*b*c</code></pre></h1></div>

<script>alert(1);</script>", "test");
            }
            Logger.UnregisterListener(listener);
            Assert.Equal(@"<div><i>x</i><EM>y</EM><h1>z<pre><code>a*b*c</code></pre></h1></div>

<script>alert(1);</script>".Replace("\r\n", "\n"), result);
            Assert.Equal(8, listener.Items.Count);
            Assert.Equal(new[]
            {
                HtmlMarkdownTokenValidatorProvider.WarningMessage,
                "Invalid tag(div)!",
                "Invalid tag(EM)!",
                "Warning tag(h1)!",
                "Warning tag(pre)!",
                "Warning tag(h1)!",
                "Html Tag!",
                "Warning tag(script)!",
            }, from item in listener.Items select item.Message);
        }