/// <summary>
        /// converts markdown to plain text
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        private string ToPlainText(string text)
        {
            var parser  = new MarkdownParserMarkdig(false);
            var builder = parser.CreatePipelineBuilder();

            text = Markdown.ToPlainText(text, builder.Build());

            return(text);
        }
Exemple #2
0
        /// <summary>
        /// Retrieves a cached instance of the markdown parser
        /// </summary>
        /// <param name="forceLoad">Forces the parser to be reloaded - otherwise previously loaded instance is used</param>
        /// <param name="usePragmaLines">If true adds pragma line ids into the document that the editor can sync to</param>
        /// <param name="parserAddinId">optional addin id that checks for a registered Markdown parser</param>
        /// <returns>Mardown Parser Interface</returns>
        public static IMarkdownParser GetParser(bool usePragmaLines = false,
                                                bool forceLoad      = false, string parserAddinId = null)
        {
            if (!forceLoad && CurrentParser != null)
            {
                return(CurrentParser);
            }

            IMarkdownParser parser = null;

            if (!string.IsNullOrEmpty(parserAddinId) && parserAddinId != DefaultMarkdownParserName)
            {
                var addin = AddinManager.Current.AddIns.FirstOrDefault(a => a.Name == parserAddinId || a.Id == parserAddinId);
                if (addin != null)
                {
                    parser = addin.GetMarkdownParser();
                }
            }

            CurrentParser = parser ?? (parser = new MarkdownParserMarkdig(usePragmaLines: usePragmaLines, force: forceLoad));

            return(CurrentParser);
        }