Beispiel #1
0
        public void RegisterPostConversion(
            string regexPattern,
            string regexReplace,
            bool ignoreCase = true,
            bool multiline  = true)
        {
            var converterHook = new RegexReplaceConverterHook(
                regexPattern,
                regexReplace,
                ConverterHookType.PostConversion,
                ignoreCase,
                multiline);

            this.Register(converterHook);
        }
Beispiel #2
0
        private static IEnumerable <IConverterHook> GetDefaultConverterHooks()
        {
            // https://help.github.com/articles/github-flavored-markdown

            var strikeThrough = new RegexReplaceConverterHook(
                @"~~(.*)~~",
                "<del>$1</del>",
                ConverterHookType.PreConversion);

            yield return(strikeThrough);

            var shortWikiLinks = new RegexReplaceConverterHook(
                @"(?:\[([^\]]+)\]\(([^\)]+)\))",
                @"<a href=""/wiki/$2/"">$1</a>",
                ConverterHookType.PreConversion);

            yield return(shortWikiLinks);

            var wikiLinks = new RegexReplaceConverterHook(
                @"^<a([^>]+)href=""(\/[^""]+)""([^>]*)>([^<]*)<\/a>$",
                @"<a$1href=""/wiki$2""$3>$4</a>",
                ConverterHookType.PreConversion);

            yield return(wikiLinks);

            for (int i = 5; i >= 1; i--)
            {
                string pattern = string.Format(@"^<h{0}([^>]*)>([^<]*)<\/h{0}>$", i);
                string replace = string.Format("<h{0}$1>$2</h{0}>", i + 1);
                yield return(new RegexReplaceConverterHook(pattern, replace, ConverterHookType.PostConversion));
            }

            var externalLinks =
                new RegexReplaceConverterHook(
                    @"<a((?:[^>]*)href=""(?:https?|ftp):\/\/(?:[^""]*)""[^>]*)>([^<]*)<\/a>",
                    @"<a$1 class=""external-link"">$2<small class=""glyphicon glyphicon-globe""></small></a>",
                    ConverterHookType.PostConversion);

            yield return(externalLinks);

            yield return(new HeadingsConverterHook());

            yield return(new TocConverterHook());
        }
Beispiel #3
0
 public void Register(RegexReplaceConverterHook converterHook)
 {
     this.converterHooks.Add(converterHook);
 }