Ejemplo n.º 1
0
        internal IMarkdownProvider StdDefinitions()
        {
            return(MarkdownProvider.Create(
                       new MarkdownNodeDefinition <MarkdownParseArgs>(@"\[\[", (args, start, end, inners) => new TextNode("[")),
                       new MarkdownNodeDefinition <MarkdownParseArgs>(@"\]\]", (args, start, end, inners) => new TextNode("]")),

                       _parser.Wrap("**", "b"),
                       _parser.Wrap("*", "i"),
                       _parser.Wrap("_", "u"),

                       heading(@"\-\-", "h1"),
                       heading(@"\-", "h2"),

                       _parser.ComplexTag("c", true, new[] { "" }, (ctx, atrs) => new Range <string> {
                Start = "<span class=\"" + atrs.ValueOrDefault("") + "\">",
                End = "</span>"
            }),

                       _parser.ComplexTag("s", true, new[] { "" }, (ctx, atrs) => new Range <string> {
                Start = "<span style=\"" + atrs.ValueOrDefault("") + "\">",
                End = "</span>"
            }),

                       _parser.ComplexTag("url", true, new[] { "" }, (ctx, atrs) => new Range <string> {
                Start = "<a href=\"" + atrs.ValueOrDefault("") + "\">",
                End = "</a>"
            }),

                       _parser.ComplexTag("anchor", false, new[] { "" }, (ctx, atrs, _) => "<a name=\"" + atrs.ValueOrDefault("") + "\"></a>"),
                       _parser.ComplexTag("jump", true, new[] { "" }, (ctx, atrs) => new Range <string> {
                Start = "<a href=\"#" + atrs.ValueOrDefault("") + "\">", End = "</a>"
            }),

                       // List
                       new MarkdownNodeDefinition <MarkdownParseArgs>(@"((?<=([\n\r]+|^)((?![\r\n])\s)*([^\s\*\r\n][^\r\n]+){0,1})(\r\n|\n\r|\r|\n)(?=((?![\r\n])\s)+\*))|(^(?=\s+\*))", @"(?<=(\r\n|\n\r|\r|\n)|$)(?!\s+\*)", (ctx, _, __, inners) => new WrapNode("ul", inners)),

                       // List item
                       new MarkdownNodeDefinition <MarkdownParseArgs>(@"(?<=([\n\r]+)|^)((?![\r\n])\s)+\*(?=[^\r\n]+)", @"(?<=(([\n\r]+)|^)((?![\r\n])\s)+\*[^\r\n]+)((\r\n|\n\r|\r|\n)|$)", (ctx, _, __, inners) => new WrapNode("li", inners)),

                       Video.VideoBBTag(),
                       Video.PlaylistBBTag(),
                       Attachments.BBImageTag(),
                       Attachments.BBFileTag(),

                       _parser.ComplexTag("html", true, new string[0], (ctx, attrs, inners) => {
                var f = inners.FirstOrDefault();
                var l = inners.LastOrDefault();
                return f == null ? "" : f.SourceString.Substring(f.SourceStartIndex, l.SourceEndIndex - f.SourceStartIndex);
            }),

                       new MarkdownNodeDefinition <MarkdownParseArgs>(@"&[^;\s]+;", (ctx, regex, _, __) => new TextNode(regex.Value, false)),

                       new MarkdownNodeDefinition <MarkdownParseArgs>(@"\r\n|\n\r|\n|\r", (ctx, regex, _, __) => new TextNode("<br/>", false)),

                       // Legacy:
                       _parser.SimpleTag("b"), _parser.SimpleTag("i"), _parser.SimpleTag("u"),
                       _parser.SimpleTag("h", "h2"), _parser.SimpleTag("h1")));
        }