Beispiel #1
0
            public DfmService(
                DfmServiceProvider provider,
                string baseDir,
                string templateDir,
                ICompositionContainer container,
                ImmutableDictionary <string, string> tokens,
                IReadOnlyList <string> fallbackFolders,
                IReadOnlyDictionary <string, object> parameters)
            {
                var options = DocfxFlavoredMarked.CreateDefaultOptions();

                options.LegacyMode             = provider.LegacyMode;
                options.ShouldFixId            = provider.ShouldFixId;
                options.ShouldExportSourceInfo = true;
                _builder = new DfmEngineBuilder(
                    options,
                    baseDir,
                    templateDir,
                    fallbackFolders,
                    container);
                _builder.TokenTreeValidator = MarkdownTokenTreeValidatorFactory.Combine(provider.TokenTreeValidator);
                _tokens   = tokens;
                _renderer = CustomizedRendererCreator.CreateRenderer(new DfmRenderer {
                    Tokens = _tokens
                }, provider.DfmRendererPartProviders, parameters);
                foreach (var c in provider.DfmEngineCustomizers)
                {
                    c.Customize(_builder, parameters);
                }
                _incrementalContextHash = ComputeIncrementalContextHash(baseDir, templateDir, provider.TokenTreeValidator, parameters);
            }
Beispiel #2
0
        public void TestRendererCreator()
        {
            var p        = new TestDfmRendererPartProvider();
            var renderer = CustomizedRendererCreator.CreateRenderer(
                new DfmRenderer(),
                new[] { p },
                null);
            var engine = DocfxFlavoredMarked
                         .CreateBuilder(".")
                         .CreateDfmEngine(renderer);
            var result = engine.Markup(@"```cs
public void TestRendererCreator()
```
```cs-x
public void TestRendererCreator()
```", "a.md");

            Assert.Equal(@"<pre><code class=""lang-cs"">public void TestRendererCreator()
</code></pre><pre class=""x""><code class=""lang-cs"">public void TestRendererCreator()
</code></pre>".Replace("\r\n", "\n"), result);
            (renderer as IDisposable).Dispose();
            Assert.True(p.CodeRendererPartInstance.Disposed);
        }
Beispiel #3
0
        public void TestRendererCreator()
        {
            var content = @"namespace ConsoleApplication1
{
    // <namespace>
    using System;
    using System.Collections.Generic;
    using System.IO;
    // </namespace>

    // <snippetprogram>
    class Program
    {
        static void Main(string[] args)
        {
            string s = ""\ntest"";
            int i = 100;
        }
    }
    // </snippetprogram>

    #region Helper
    internal static class Helper
    {
        #region Foo
        public static void Foo()
        {
        }
        #endregion Foo
    }
    #endregion
}";

            File.WriteAllText("Program.csdocfx", content.Replace("\r\n", "\n"));
            var p        = new TestDfmRendererPartProvider();
            var renderer = CustomizedRendererCreator.CreateRenderer(
                new DfmRenderer(),
                new[] { p },
                null);
            var engine = DocfxFlavoredMarked
                         .CreateBuilder(".")
                         .CreateDfmEngine(renderer);
            var result = engine.Markup(@"```cs
public void TestRendererCreator()
```
```cs-x
public void TestRendererCreator()
```
[!code-csdocfx[Main](Program.csdocfx#namespace ""This is root"")]
[!code-cs-xyz[](Program.csdocfx#Foo)]", "a.md");

            Assert.Equal(@"<pre><code class=""lang-cs"">public void TestRendererCreator()
</code></pre><pre class=""x""><code class=""lang-cs"">public void TestRendererCreator()
</code></pre><pre><code class=""lang-csdocfx"" name=""Main"" title=""This is root"">using System;
using System.Collections.Generic;
using System.IO;
</code></pre><pre><code class=""lang-cs-xyz"">public static void Foo()
{
}
</code></pre>".Replace("\r\n", "\n"), result);
            (renderer as IDisposable).Dispose();
            Assert.True(p.CodeRendererPartInstance.Disposed);
            if (File.Exists("Program.csdocfx"))
            {
                File.Delete("Program.csdocfx");
            }
        }