public MarkdownRendererAdapter(IMarkdownEngine engine, object renderer, Options options, Dictionary<string, LinkObj> links)
 {
     Engine = engine;
     Renderer = renderer;
     Options = options;
     Links = links;
 }
示例#2
0
        public DfmEngineBuilder(Options options) : base(options)
        {
            var inlineRules = InlineRules.ToList();

            var index = inlineRules.FindLastIndex(s => s is MarkdownLinkInlineRule);
            if (index < 0) throw new ArgumentException("MarkdownLinkInlineRule should exist!");
            inlineRules.Insert(index + 1, new DfmXrefInlineRule());
            inlineRules.Insert(index, new DfmIncludeInlineRule());
            index = inlineRules.FindIndex(s => s is MarkdownTextInlineRule);
            inlineRules[index] = new DfmTextInlineRule();

            var blockRules = BlockRules.ToList();
            index = blockRules.FindLastIndex(s => s is MarkdownNewLineBlockRule);
            if (index < 0) throw new ArgumentException("MarkdownNewLineBlockRule should exist!");
            blockRules.Insert(index + 1, new DfmIncludeBlockRule());
            blockRules.Insert(index + 2, new DfmYamlHeaderBlockRule());
            blockRules.Insert(index + 3, new DfmSectionBeginBlockRule());
            blockRules.Insert(index + 4, new DfmFencesBlockRule());
            blockRules.Insert(index + 5, new DfmNoteBlockRule());
            blockRules.Insert(index + 6, new DfmSectionEndBlockRule());

            var gfmIndex = blockRules.FindIndex(item => item is GfmParagraphBlockRule);
            blockRules[gfmIndex] = new DfmParagraphBlockRule();

            var markdownBlockQuoteIndex = blockRules.FindIndex(item => item is MarkdownBlockquoteBlockRule);
            blockRules[markdownBlockQuoteIndex] = new DfmBlockquoteBlockRule();

            InlineRules = inlineRules.ToImmutableList();
            BlockRules = blockRules.ToImmutableList();
        }
示例#3
0
 protected MarkdownEngine(IMarkdownContext context, IMarkdownTokenRewriter rewriter, object renderer, Options options, Dictionary<string, LinkObj> links)
 {
     Context = context;
     Rewriter = rewriter ?? MarkdownTokenRewriterFactory.Null;
     RendererImpl = renderer;
     Options = options;
     Links = links;
 }
示例#4
0
        public static string GetRenderedFencesBlockString(DfmFencesBlockToken token, Options options, string errorMessage, string[] codeLines = null)
        {
            string renderedErrorMessage = string.Empty;
            string renderedCodeLines = string.Empty;
            if (!string.IsNullOrEmpty(errorMessage))
            {
                renderedErrorMessage = $@"<!-- {StringHelper.HtmlEncode(errorMessage)} -->\n";
            }

            if (codeLines != null)
            {
                var lang = string.IsNullOrEmpty(token.Lang) ? null : $" class=\"{options.LangPrefix}{token.Lang}\"";
                var name = string.IsNullOrEmpty(token.Name) ? null : $" name=\"{StringHelper.HtmlEncode(token.Name)}\"";
                var title = string.IsNullOrEmpty(token.Title) ? null : $" title=\"{StringHelper.HtmlEncode(token.Title)}\"";

                renderedCodeLines = $"<pre><code{lang}{name}{title}>{StringHelper.HtmlEncode(string.Join("\n", codeLines))}\n</code></pre>";
            }

            return $"{renderedErrorMessage}{renderedCodeLines}";
        }
示例#5
0
        public DfmEngineBuilder(Options options) : base(options)
        {
            var inlineRules = InlineRules.ToList();

            // xref auto link must be before MarkdownAutoLinkInlineRule
            var index = inlineRules.FindIndex(s => s is MarkdownAutoLinkInlineRule);
            if (index < 0) throw new ArgumentException("MarkdownAutoLinkInlineRule should exist!");
            inlineRules.Insert(index, new DfmXrefAutoLinkInlineRule());

            index = inlineRules.FindLastIndex(s => s is MarkdownLinkInlineRule);
            if (index < 0) throw new ArgumentException("MarkdownLinkInlineRule should exist!");
            inlineRules.Insert(index + 1, new DfmXrefShortcutInlineRule());
            inlineRules.Insert(index + 1, new DfmEmailInlineRule());

            // xref link inline rule must be before MarkdownLinkInlineRule
            inlineRules.Insert(index, new DfmXrefLinkInlineRule());
            inlineRules.Insert(index, new DfmIncludeInlineRule());

            index = inlineRules.FindIndex(s => s is MarkdownTextInlineRule);
            inlineRules[index] = new DfmTextInlineRule();

            var blockRules = BlockRules.ToList();
            index = blockRules.FindLastIndex(s => s is MarkdownNewLineBlockRule);
            if (index < 0) throw new ArgumentException("MarkdownNewLineBlockRule should exist!");
            blockRules.Insert(index + 1, new DfmIncludeBlockRule());
            blockRules.Insert(index + 2, new DfmYamlHeaderBlockRule());
            blockRules.Insert(index + 3, new DfmSectionBlockRule());
            blockRules.Insert(index + 4, new DfmFencesBlockRule());
            blockRules.Insert(index + 5, new DfmNoteBlockRule());

            var gfmIndex = blockRules.FindIndex(item => item is GfmParagraphBlockRule);
            blockRules[gfmIndex] = new DfmParagraphBlockRule();

            var markdownBlockQuoteIndex = blockRules.FindIndex(item => item is MarkdownBlockquoteBlockRule);
            blockRules[markdownBlockQuoteIndex] = new DfmBlockquoteBlockRule();

            InlineRules = inlineRules.ToImmutableList();
            BlockRules = blockRules.ToImmutableList();

            Rewriter = InitMarkdownStyle(GetContainer());
        }
示例#6
0
        /// <summary>
        /// Smartypants Transformations
        /// </summary>
        protected virtual string Smartypants(Options options, string text)
        {
            if (!options.Smartypants)
            {
                return text;
            }

            return text
                // em-dashes
                .Replace("---", "\u2014")
                // en-dashes
                .Replace("--", "\u2013")
                // opening singles
                .ReplaceRegex(Regexes.Inline.Smartypants.OpeningSingles, "$1\u2018")
                // closing singles & apostrophes
                .Replace("'", "\u2019")
                // opening doubles
                .ReplaceRegex(Regexes.Inline.Smartypants.OpeningDoubles, "$1\u201c")
                // closing doubles
                .Replace("\"", "\u201d")
                // ellipses
                .Replace("...", "\u2026");
        }
 public MarkdownEngineByOptionsBuilder(Options options)
     : base(options)
 {
     BuildRulesByOptions();
 }
示例#8
0
 public MarkdownEngine(IMarkdownContext context, IMarkdownTokenRewriter rewriter, object renderer, Options options)
     : this(context, rewriter, renderer, options, new Dictionary<string, LinkObj>())
 {
 }
示例#9
0
 public MarkdownParser(IMarkdownContext context, Options options, Dictionary<string, LinkObj> links)
 {
     Context = context;
     Options = options;
     Links = links;
 }
示例#10
0
        public DfmEngineBuilder(Options options, string baseDir = null, string templateDir = null, IReadOnlyList<string> fallbackFolders = null) : base(options)
        {
            _baseDir = baseDir ?? string.Empty;
            _fallbackFolders = fallbackFolders ?? new List<string>();
            var inlineRules = InlineRules.ToList();

            // xref auto link must be before MarkdownAutoLinkInlineRule
            var index = inlineRules.FindIndex(s => s is MarkdownAutoLinkInlineRule);
            if (index < 0)
            {
                throw new ArgumentException("MarkdownAutoLinkInlineRule should exist!");
            }
            inlineRules.Insert(index, new DfmXrefAutoLinkInlineRule());

            index = inlineRules.FindLastIndex(s => s is MarkdownLinkInlineRule);
            if (index < 0)
            {
                throw new ArgumentException("MarkdownLinkInlineRule should exist!");
            }
            inlineRules.Insert(index + 1, new DfmXrefShortcutInlineRule());
            inlineRules.Insert(index + 1, new DfmEmailInlineRule());
            inlineRules.Insert(index + 1, new DfmFencesInlineRule());

            // xref link inline rule must be before MarkdownLinkInlineRule
            inlineRules.Insert(index, new DfmIncludeInlineRule());

            index = inlineRules.FindIndex(s => s is MarkdownTextInlineRule);
            if (index < 0)
            {
                throw new ArgumentException("MarkdownTextInlineRule should exist!");
            }
            inlineRules[index] = new DfmTextInlineRule();

            var blockRules = BlockRules.ToList();
            index = blockRules.FindLastIndex(s => s is MarkdownCodeBlockRule);
            if (index < 0)
            {
                throw new ArgumentException("MarkdownNewLineBlockRule should exist!");
            }

            blockRules.InsertRange(
                index + 1,
                new IMarkdownRule[]
                {
                    new DfmIncludeBlockRule(),
                    new DfmVideoBlockRule(),
                    new DfmYamlHeaderBlockRule(),
                    new DfmSectionBlockRule(),
                    new DfmFencesBlockRule(),
                    new DfmNoteBlockRule()
                });

            var markdownBlockQuoteIndex = blockRules.FindIndex(item => item is MarkdownBlockquoteBlockRule);
            if (markdownBlockQuoteIndex < 0)
            {
                throw new ArgumentException("MarkdownBlockquoteBlockRule should exist!");
            }
            blockRules[markdownBlockQuoteIndex] = new DfmBlockquoteBlockRule();

            InlineRules = inlineRules.ToImmutableList();
            BlockRules = blockRules.ToImmutableList();

            Rewriter = InitMarkdownStyle(GetContainer(), baseDir, templateDir);
        }
示例#11
0
 public GfmEngineBuilder(Options options)
     : base(options)
 {
     BuildRules();
 }
示例#12
0
 public MarkdownEngineBuilder(Options options)
 {
     Options = options;
 }
示例#13
0
 public static string GetRenderedFencesBlockString(DfmFencesBlockToken token, Options options,
     string errorMessage, string[] codeLines = null)
     => GetRenderedFencesBlockString((DfmFencesToken)token, options, errorMessage, codeLines);
示例#14
0
 public static DfmEngineBuilder CreateBuilder(string baseDir, string templateDir, Options options, IReadOnlyList<string> fallbackFolders) =>
     new DfmEngineBuilder(options ?? CreateDefaultOptions(), baseDir, templateDir, fallbackFolders);
示例#15
0
 public MarkdownEngine(IMarkdownContext context, object renderer, Options options)
     : this(context, null, renderer, options, new Dictionary<string, LinkObj>())
 {
 }
 public MarkdownEngineByOptionsBuilder(Options options)
     : base(options)
 {
     BuildRulesByOptions();
 }
示例#17
0
 public static string Markup(string baseDir, string templateDir, Options options, string src, string path = null, ImmutableDictionary<string, string> tokens = null, HashSet<string> dependency = null)
 {
     var engine = CreateBuilder(baseDir, templateDir, options ?? CreateDefaultOptions()).CreateDfmEngine(new DfmRenderer() { Tokens = tokens });
     return engine.Markup(src, path, dependency);
 }
示例#18
0
 public DfmEngine(IMarkdownContext context, IMarkdownRewriter rewriter, object renderer, Options options) : base(context, rewriter, renderer, options)
 {
 }
示例#19
0
 public MarkdownParser(IMarkdownContext context, Options options, Dictionary <string, LinkObj> links)
 {
     Context = context;
     Options = options;
     Links   = links;
 }
示例#20
0
 public AzureEngineBuilder(Options options) : base(options)
 {
     BuildRules();
     CreateRewriters();
 }
示例#21
0
 public static DfmEngineBuilder CreateBuilder(string baseDir, string templateDir, Options options) =>
     new DfmEngineBuilder(options ?? CreateDefaultOptions(), baseDir, templateDir, null);