public override MarkdownPipeline GetPipeline()
        {
            var pipelineBuilder = new MarkdownPipelineBuilder();

            if (PipeTables) pipelineBuilder = pipelineBuilder.UsePipeTables();
            if (GridTables) pipelineBuilder = pipelineBuilder.UseGridTables();
            if (ExtraEmphasis) pipelineBuilder = pipelineBuilder.UseEmphasisExtras();
            if (DefinitionLists) pipelineBuilder = pipelineBuilder.UseDefinitionLists();
            if (Footnotes) pipelineBuilder = pipelineBuilder.UseFootnotes();
            if (TaskLists) pipelineBuilder = pipelineBuilder.UseTaskLists();
            if (ExtraBulletLists) pipelineBuilder = pipelineBuilder.UseListExtras();
            if (Abbreviations) pipelineBuilder = pipelineBuilder.UseAbbreviations();
            if (Emoji) pipelineBuilder = pipelineBuilder.UseEmojiAndSmiley();

            return pipelineBuilder.Build();
        }
        public override MarkdownPipeline GetPipeline()
        {
            var pipelineBuilder = new MarkdownPipelineBuilder();

            if (PipeTables)
            {
                pipelineBuilder = pipelineBuilder.UsePipeTables();
            }
            if (GridTables)
            {
                pipelineBuilder = pipelineBuilder.UseGridTables();
            }
            if (ExtraEmphasis)
            {
                pipelineBuilder = pipelineBuilder.UseEmphasisExtras();
            }
            if (DefinitionLists)
            {
                pipelineBuilder = pipelineBuilder.UseDefinitionLists();
            }
            if (Footnotes)
            {
                pipelineBuilder = pipelineBuilder.UseFootnotes();
            }
            if (TaskLists)
            {
                pipelineBuilder = pipelineBuilder.UseTaskLists();
            }
            if (ExtraBulletLists)
            {
                pipelineBuilder = pipelineBuilder.UseListExtras();
            }
            if (Abbreviations)
            {
                pipelineBuilder = pipelineBuilder.UseAbbreviations();
            }
            if (Emoji)
            {
                pipelineBuilder = pipelineBuilder.UseEmojiAndSmiley();
            }

            return(pipelineBuilder.Build());
        }
        public virtual MarkdownPipeline GetPipeline()
        {
            MediaOptions mediaOptions = new MediaOptions();

            mediaOptions.Hosts.Add(new BilibiliMediaLinkHost());
            mediaOptions.Hosts.Add(new NeteaseMusicMediaLinkHost());

            var builder = new MarkdownPipelineBuilder();

            builder.UseAbbreviations()
            .UseAutoIdentifiers()
            .UseCitations()
            .UseCustomContainers()
            .UseDefinitionLists()
            .UseEmphasisExtras()
            .UseFigures()
            .UseFooters()
            .UseFootnotes()
            .UseGridTables()
            .UseMediaLinks(mediaOptions)
            .UsePipeTables()
            .UseListExtras()
            .UseTaskLists()
            .UseAutoLinks()
            .UseSmartyPants()
            .UseEmojiAndSmiley();
            // .UseBootstrap()

            if (EnableMathematics)
            {
                builder.UseMathematics();
            }
            if (EnableDiagrams)
            {
                builder.UseDiagrams();
            }

            builder.UseGenericAttributes(); // Must be last as it is one parser that is modifying other parsers
            return(builder.Build());
        }
Ejemplo n.º 4
0
 private static MarkdownPipelineBuilder UseAdvancedExtensions(MarkdownPipelineBuilder pipeline)
 {
     return(pipeline
            .UseAbbreviations()
            .UseAutoIdentifiers(AutoIdentifierOptions.AllowOnlyAscii)
            .UseCitations()
            .UseCustomContainers()
            .UseDefinitionLists()
            .UseEmphasisExtras()
            .UseFigures()
            .UseFooters()
            .UseFootnotes()
            .UseGridTables()
            .UseMathematics()
            .UseMediaLinks()
            .UsePipeTables()
            .UseListExtras()
            .UseTaskLists()
            .UseDiagrams()
            .UseAutoLinks()
            .UseGenericAttributes()
            .Use <QuoteSectionNoteExtension>()); // Must be last as it is one parser that is modifying other parsers
 }
        /// <summary>
        /// Builds the Markdig processing pipeline and returns a builder.
        /// Use this method to override any custom pipeline addins you want to
        /// add or append.
        ///
        /// Note you can also add addins using options.MarkdigExtensions which
        /// use MarkDigs extension syntax using commas instead of +.
        /// </summary>
        /// <param name="options"></param>
        /// <param name="builder"></param>
        /// <returns></returns>
        protected virtual MarkdownPipelineBuilder BuildPipeline(MarkdownOptionsConfiguration options, MarkdownPipelineBuilder builder)
        {
            if (options.AutoLinks)
            {
                builder = builder.UseAutoLinks();
            }
            if (options.AutoHeaderIdentifiers)
            {
                builder = builder.UseAutoIdentifiers();
            }
            if (options.Abbreviations)
            {
                builder = builder.UseAbbreviations();
            }

            if (options.StripYamlFrontMatter)
            {
                builder = builder.UseYamlFrontMatter();
            }
            if (options.EmojiAndSmiley)
            {
                builder = builder.UseEmojiAndSmiley();
            }
            if (options.MediaLinks)
            {
                builder = builder.UseMediaLinks();
            }
            if (options.ListExtras)
            {
                builder = builder.UseListExtras();
            }
            if (options.Figures)
            {
                builder = builder.UseFigures();
            }
            if (options.GithubTaskLists)
            {
                builder = builder.UseTaskLists();
            }
            if (options.SmartyPants)
            {
                builder = builder.UseSmartyPants();
            }
            if (options.Diagrams)
            {
                builder = builder.UseDiagrams();
            }

            if (UsePragmaLines)
            {
                builder = builder.UsePragmaLines();
            }

            try
            {
                if (!string.IsNullOrWhiteSpace(options.MarkdigExtensions))
                {
                    builder = builder.Configure(options.MarkdigExtensions.Replace(",", "+"));
                }
            }
            catch (ArgumentException ex)
            {
                // One or more of the extension options is invalid.
                mmApp.Log("Failed to load Markdig extensions: " + options.MarkdigExtensions + "\r\n" + ex.Message, ex);
            }

            return(builder);
        }
        protected virtual MarkdownPipelineBuilder CreatePipelineBuilder()
        {
            var builder = new MarkdownPipelineBuilder()
                          .UseEmphasisExtras()
                          .UsePipeTables()
                          .UseGridTables()
                          .UseFooters()
                          .UseFootnotes()
                          .UseCitations();


            var options = mmApp.Configuration.MarkdownOptions;

            if (options.AutoLinks)
            {
                builder = builder.UseAutoLinks();
            }
            if (options.AutoHeaderIdentifiers)
            {
                builder = builder.UseAutoIdentifiers();
            }
            if (options.Abbreviations)
            {
                builder = builder.UseAbbreviations();
            }

            if (options.StripYamlFrontMatter)
            {
                builder = builder.UseYamlFrontMatter();
            }
            if (options.EmojiAndSmiley)
            {
                builder = builder.UseEmojiAndSmiley();
            }
            if (options.MediaLinks)
            {
                builder = builder.UseMediaLinks();
            }
            if (options.ListExtras)
            {
                builder = builder.UseListExtras();
            }
            if (options.Figures)
            {
                builder = builder.UseFigures();
            }
            if (options.GithubTaskLists)
            {
                builder = builder.UseTaskLists();
            }
            if (options.SmartyPants)
            {
                builder = builder.UseSmartyPants();
            }

            if (_usePragmaLines)
            {
                builder = builder.UsePragmaLines();
            }

            return(builder);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Builds the Markdig processing pipeline and returns a builder.
        /// Use this method to override any custom pipeline addins you want to
        /// add or append.
        ///
        /// Note you can also add addins using options.MarkdigExtensions which
        /// use MarkDigs extension syntax using commas instead of +.
        /// </summary>
        /// <param name="options"></param>
        /// <param name="builder"></param>
        /// <returns></returns>
        protected virtual MarkdownPipelineBuilder BuildPipeline(MarkdownOptionsConfiguration options, MarkdownPipelineBuilder builder)
        {
            if (options.AutoLinks)
            {
                builder = builder.UseAutoLinks();
            }
            if (options.AutoHeaderIdentifiers)
            {
                builder = builder.UseAutoIdentifiers(Markdig.Extensions.AutoIdentifiers.AutoIdentifierOptions.GitHub);
            }
            if (options.Abbreviations)
            {
                builder = builder.UseAbbreviations();
            }

            if (options.UseTables)
            {
                builder = builder
                          .UsePipeTables()
                          .UseGridTables();
            }

            if (options.StripYamlFrontMatter)
            {
                builder = builder.UseYamlFrontMatter();
            }
            if (options.EmojiAndSmiley)
            {
                builder = builder.UseEmojiAndSmiley(true);
            }
            if (options.MediaLinks)
            {
                builder = builder.UseMediaLinks();
            }
            if (options.ListExtras)
            {
                builder = builder.UseListExtras();
            }
            if (options.Figures)
            {
                builder = builder.UseFigures();
            }
            if (options.GithubTaskLists)
            {
                builder = builder.UseTaskLists();
            }
            if (options.SmartyPants)
            {
                builder = builder.UseSmartyPants();
            }
            if (options.Diagrams)
            {
                builder = builder.UseDiagrams();
            }
            if (options.CustomContainers)
            {
                builder = builder.UseCustomContainers();
            }
            if (options.Attributes)
            {
                builder = builder.UseGenericAttributes();
            }
            if (options.FootersAndFootnotes)
            {
                builder = builder
                          .UseFooters()
                          .UseFootnotes();
            }
            if (options.NoHtml)
            {
                builder = builder.DisableHtml();
            }

            builder = builder.UseEmphasisExtras();

            if (UsePragmaLines)
            {
                builder = builder.UsePragmaLines();
            }

            try
            {
                if (!string.IsNullOrWhiteSpace(options.MarkdigExtensions))
                {
                    builder = builder.Configure(options.MarkdigExtensions.Replace(",", "+"));
                }
            }
            catch (ArgumentException ex)
            {
                // One or more of the extension options is invalid.
                mmApp.Log("Failed to load Markdig extensions: " + options.MarkdigExtensions + "\r\n" + ex.Message, ex);

                // reset to default
                options.MarkdigExtensions = string.Empty;
                builder = builder.Configure(options.MarkdigExtensions.Replace(",", "+"));
            }

            return(builder);
        }
        private static MarkdownPipelineBuilder BuildPipeline(bool useAbbreviations, bool useAutoIdentifiers, bool useCitations, bool useCustomContainers,
                                                             bool useEmojiAndSmiley, bool useEmphasisExtras, bool useFigures, bool useFootnotes,
                                                             bool useGenericAttributes, bool useGridTables, bool useListExtras, bool useMediaLinks,
                                                             bool usePipeTables, bool usePragmaLines, bool useSmartyPants, bool useTaskLists,
                                                             bool useYamlFrontMatter, bool useAutoLinks)
        {
            var builder = new MarkdownPipelineBuilder();

            if (useAbbreviations)
            {
                builder = builder.UseAbbreviations();
            }
            if (useAutoIdentifiers)
            {
                builder = builder.UseAutoIdentifiers(AutoIdentifierOptions.GitHub);
            }
            if (useCitations)
            {
                builder = builder.UseCitations();
            }
            if (useCustomContainers)
            {
                builder = builder.UseCustomContainers();
            }
            if (useEmojiAndSmiley)
            {
                builder = builder.UseEmojiAndSmiley();
            }
            if (useEmphasisExtras)
            {
                builder = builder.UseEmphasisExtras();
            }
            if (useFigures)
            {
                builder = builder.UseFigures();
            }
            if (useFootnotes)
            {
                builder = builder.UseFootnotes();
            }
            if (useGenericAttributes)
            {
                builder = builder.UseGenericAttributes();
            }
            if (useGridTables)
            {
                builder = builder.UseGridTables();
            }
            if (useListExtras)
            {
                builder = builder.UseListExtras();
            }

            if (useMediaLinks)
            {
                builder = builder.UseMediaLinks();
            }
            if (usePipeTables)
            {
                builder = builder.UsePipeTables();
            }
            if (usePragmaLines)
            {
                builder = builder.UsePragmaLines();
            }
            if (useSmartyPants)
            {
                builder = builder.UseSmartyPants();
            }
            if (useTaskLists)
            {
                builder = builder.UseTaskLists();
            }
            if (useYamlFrontMatter)
            {
                builder = builder.UseYamlFrontMatter();
            }

            if (useAutoLinks)
            {
                builder = builder.UseAutoLinks();
            }

            return(builder);
        }
Ejemplo n.º 9
0
        protected virtual MarkdownPipelineBuilder BuildPipeline(MarkdownPipelineBuilder builder, ISettingsProvider settings, string markdown)
        {
            if (settings.GetSetting <bool>(SettingsEnum.UseAbbreviations))
            {
                builder = builder.UseAbbreviations();
            }
            if (settings.GetSetting <bool>(SettingsEnum.UseAutoIdentifiers))
            {
                builder = builder.UseAutoIdentifiers(AutoIdentifierOptions.GitHub);
            }
            //if (settings.GetSetting<bool>(SettingsEnum.UseAutoLinks)) builder = builder.UseAutoLinks();
            if (settings.GetSetting <bool>(SettingsEnum.UseCitations))
            {
                builder = builder.UseCitations();
            }
            if (settings.GetSetting <bool>(SettingsEnum.UseCustomContainers))
            {
                builder = builder.UseCustomContainers();
            }
            if (settings.GetSetting <bool>(SettingsEnum.UseEmojiAndSmiley))
            {
                builder = builder.UseEmojiAndSmiley();
            }
            if (settings.GetSetting <bool>(SettingsEnum.UseEmphasisExtras))
            {
                builder = builder.UseEmphasisExtras();
            }
            if (settings.GetSetting <bool>(SettingsEnum.UseFigures))
            {
                builder = builder.UseFigures();
            }
            if (settings.GetSetting <bool>(SettingsEnum.UseFootnotes))
            {
                builder = builder.UseFootnotes();
            }
            if (settings.GetSetting <bool>(SettingsEnum.UseGenericAttributes) && !settings.GetSetting <bool>(SettingsEnum.UseMathematics))
            {
                builder = builder.UseGenericAttributes();
            }
            if (settings.GetSetting <bool>(SettingsEnum.UseGridTables))
            {
                builder = builder.UseGridTables();
            }
            if (settings.GetSetting <bool>(SettingsEnum.UseListExtras))
            {
                builder = builder.UseListExtras();
            }

            //if (settings.GetSetting<bool>(SettingsEnum.UseMathematics)) builder = builder.UseMathematics();
            if (settings.GetSetting <bool>(SettingsEnum.UseMathematics))
            {
                builder = builder.UseMathJax();
            }

            if (settings.GetSetting <bool>(SettingsEnum.UseMediaLinks))
            {
                builder = builder.UseMediaLinks();
            }
            if (settings.GetSetting <bool>(SettingsEnum.UsePipeTables))
            {
                builder = builder.UsePipeTables();
            }
            if (settings.GetSetting <bool>(SettingsEnum.UsePragmaLines))
            {
                builder = builder.UsePragmaLines();
            }
            if (settings.GetSetting <bool>(SettingsEnum.UseSmartyPants))
            {
                builder = builder.UseSmartyPants();
            }
            if (settings.GetSetting <bool>(SettingsEnum.UseTaskLists))
            {
                builder = builder.UseTaskLists();
            }
            if (settings.GetSetting <bool>(SettingsEnum.UseYamlFrontMatter))
            {
                builder = builder.UseYamlFrontMatter();
            }

            var containsMermaid = markdown.Contains("```mermaid");
            var containsNomnoml = markdown.Contains("```nomnoml");
            var useDiagrams     = containsMermaid || containsNomnoml;

            if (useDiagrams)
            {
                // We need to check to make sure that it isn't specifically disabled
                if (settings.IsSettingSpecified(SettingsEnum.UseDiagramsNomnoml) && !settings.GetSetting <bool>(SettingsEnum.UseDiagramsNomnoml))
                {
                    useDiagrams = false;
                }
                if (settings.IsSettingSpecified(SettingsEnum.UseDiagramsMermaid) && !settings.GetSetting <bool>(SettingsEnum.UseDiagramsMermaid))
                {
                    useDiagrams = false;
                }
                if (useDiagrams) // If we auto-use, we need to set the diagram settings to true in this instance, so subsequent processing will work correctly
                {
                    if (containsMermaid)
                    {
                        settings.OverrideSetting(SettingsEnum.UseDiagramsMermaid, true);
                    }
                    if (containsNomnoml)
                    {
                        settings.OverrideSetting(SettingsEnum.UseDiagramsNomnoml, true);
                    }
                }
            }
            else
            {
                useDiagrams = settings.GetSetting <bool>(SettingsEnum.UseDiagramsMermaid) || settings.GetSetting <bool>(SettingsEnum.UseDiagramsNomnoml);
            }

            if (useDiagrams)
            {
                builder = builder.UseDiagrams();
            }

            return(builder);
        }
Ejemplo n.º 10
0
        private async Task <MarkdownPipeline> GetMarkdownPipelineImpl(HtmlBuilder htmlBuilder)
        {
            var pipelineBuilder = new MarkdownPipelineBuilder();


            htmlBuilder.UseVSCodeMarkdownStylesheet();
            htmlBuilder.AddKeyboardListener();
            htmlBuilder.AddCharset();

            if (!await _settings.IsHtmlEnabled())
            {
                pipelineBuilder.DisableHtml();
            }
            if (await _settings.IsAbbreviationEnabled())
            {
                pipelineBuilder.UseAbbreviations();
            }
            // TODO AutoIdentifierOptions
            if (await _settings.IsAutoIdentifierEnabled())
            {
                pipelineBuilder.UseAutoIdentifiers();
            }
            if (await _settings.IsBootstrapEnabled())
            {
                pipelineBuilder.UseBootstrap();
            }
            if (await _settings.IsCitationEnabled())
            {
                pipelineBuilder.UseCitations();
            }
            if (await _settings.IsDefinitionListEnabled())
            {
                pipelineBuilder.UseDefinitionLists();
            }
            // TODO EmojiSmileyOptions
            if (await _settings.IsEmojiSmileyEnabled())
            {
                pipelineBuilder.UseEmojiAndSmiley();
            }
            if (await _settings.IsFigureEnabled())
            {
                pipelineBuilder.UseFigures();
            }
            if (await _settings.IsFooterEnabled())
            {
                pipelineBuilder.UseFooters();
            }
            if (await _settings.IsFootnoteEnabled())
            {
                pipelineBuilder.UseFootnotes();
            }
            // TODO MediaLinkOptions
            if (await _settings.IsMedialinkEnabled())
            {
                pipelineBuilder.UseMediaLinks();
            }
            if (await _settings.IsSoftlineAsHardlineBreakEnabled())
            {
                pipelineBuilder.UseSoftlineBreakAsHardlineBreak();
            }
            // TODO SmartyPantsOptions
            if (await _settings.IsSmartyPantEnabled())
            {
                pipelineBuilder.UseSmartyPants();
            }
            if (await _settings.IsGenericAttributeEnabled())
            {
                pipelineBuilder.UseGenericAttributes();
            }

            if (await _settings.IsDiagramEnabled())
            {
                pipelineBuilder.UseDiagrams();

                if (await _settings.IsMermaidEnabled())
                {
                    htmlBuilder.UseMermaid();
                }
                if (await _settings.IsNomnomlEnabled())
                {
                    htmlBuilder.UseNomnoml();
                }
            }

            if (await _settings.IsEmphasisEnabled())
            {
                EmphasisExtraOptions options = 0;

                if (await _settings.IsStrikethroughEnabled())
                {
                    options |= EmphasisExtraOptions.Strikethrough;
                }
                if (await _settings.IsInsertedEnabled())
                {
                    options |= EmphasisExtraOptions.Inserted;
                }
                if (await _settings.IsMarkedEnabled())
                {
                    options |= EmphasisExtraOptions.Marked;
                }
                if (await _settings.IsSuperSubScriptEnabled())
                {
                    options = options | EmphasisExtraOptions.Subscript | EmphasisExtraOptions.Superscript;
                }

                pipelineBuilder.UseEmphasisExtras(options);
            }

            if (await _settings.IsListEnabled())
            {
                if (await _settings.IsTaskListEnabled())
                {
                    pipelineBuilder.UseTaskLists();
                }
                if (await _settings.IsListExtraEnabled())
                {
                    pipelineBuilder.UseListExtras();
                }
            }

            if (await _settings.IsMathEnabled())
            {
                pipelineBuilder.UseMyMathExtension();
                htmlBuilder.UseMathjax();
            }

            if (await _settings.IsSyntaxHighlightingEnabled())
            {
                htmlBuilder.UsePrismSyntaxHighlighting();
            }

            if (await _settings.IsTableEnabled())
            {
                if (await _settings.IsGridTableEnabled())
                {
                    pipelineBuilder.UseGridTables();
                }
                // TODO PipeTableOptions
                if (await _settings.IsPipeTableEnabled())
                {
                    pipelineBuilder.UsePipeTables();
                }
            }

            pipelineBuilder.UseMyWikiLinkExtension();
            pipelineBuilder.UseTagExtension();
            pipelineBuilder.UseYamlFrontMatter();

            htmlBuilder.Flush();

            return(pipelineBuilder.Build());
        }