Exemplo n.º 1
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);
        }
        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);
        }
Exemplo n.º 3
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());
        }