Beispiel #1
0
        public virtual IMarkdownToken TryMatch(IMarkdownParser engine, ref string source)
        {
            var match = NpTable.Match(source);

            if (match.Length == 0)
            {
                return(null);
            }
            source = source.Substring(match.Length);
            var header = match.Groups[1].Value.ReplaceRegex(Regexes.Lexers.UselessTableHeader, string.Empty).SplitRegex(Regexes.Lexers.TableSplitter);
            var align  = ParseAligns(match.Groups[2].Value.ReplaceRegex(Regexes.Lexers.UselessTableAlign, string.Empty).SplitRegex(Regexes.Lexers.TableSplitter));
            var cells  = match.Groups[3].Value.ReplaceRegex(Regexes.Lexers.EndWithNewLine, string.Empty).Split('\n').Select(x => new string[] { x }).ToArray();

            for (int i = 0; i < cells.Length; i++)
            {
                cells[i] = cells[i][0].SplitRegex(Regexes.Lexers.TableSplitter);
            }
            return(new MarkdownTableBlockToken(
                       this,
                       engine.Context,
                       (from text in header
                        select engine.TokenizeInline(text)).ToImmutableArray(),
                       align.ToImmutableArray(),
                       (from row in cells
                        select(from col in row
                               select engine.TokenizeInline(col)).ToImmutableArray()).ToImmutableArray()));
        }
        public virtual IMarkdownToken TryMatch(IMarkdownParser engine, ref string source)
        {
            var match = NpTable.Match(source);
            if (match.Length == 0)
            {
                return null;
            }
            source = source.Substring(match.Length);
            var header = match.Groups[1].Value.ReplaceRegex(Regexes.Lexers.UselessTableHeader, string.Empty).SplitRegex(Regexes.Lexers.TableSplitter);
            var align = ParseAligns(match.Groups[2].Value.ReplaceRegex(Regexes.Lexers.UselessTableAlign, string.Empty).SplitRegex(Regexes.Lexers.TableSplitter));
            var cells = match.Groups[3].Value.ReplaceRegex(Regexes.Lexers.EndWithNewLine, string.Empty).Split('\n').Select(x => new string[] { x }).ToArray();

            for (int i = 0; i < cells.Length; i++)
            {
                cells[i] = cells[i][0].SplitRegex(Regexes.Lexers.TableSplitter);
            }
            return new MarkdownTableBlockToken(
                this,
                engine.Context,
                (from text in header
                 select engine.TokenizeInline(text)).ToImmutableArray(),
                align.ToImmutableArray(),
                (from row in cells
                 select (from col in row
                         select engine.TokenizeInline(col)).ToImmutableArray()).ToImmutableArray());
        }
Beispiel #3
0
        public virtual IMarkdownToken TryMatch(IMarkdownParser engine, ref string source)
        {
            var match = Html.Match(source);

            if (match.Length == 0)
            {
                return(null);
            }
            source = source.Substring(match.Length);

            bool isPre = engine.Options.Sanitizer == null &&
                         (match.Groups[1].Value == "pre" || match.Groups[1].Value == "script" || match.Groups[1].Value == "style");

            if (engine.Options.Sanitize)
            {
                return(new MarkdownParagraphBlockToken(this, engine.Context, engine.TokenizeInline(match.Value), match.Value));
            }
            else
            {
                return(new MarkdownHtmlBlockToken(
                           this,
                           engine.Context,
                           isPre ? new InlineContent(new IMarkdownToken[] { new MarkdownRawToken(this, engine.Context, match.Value) }.ToImmutableArray()) : engine.TokenizeInline(match.Value),
                           match.Value));
            }
        }
Beispiel #4
0
 private static IMarkdownToken CreateToken(IMarkdownParser parser, IMarkdownRule rule, bool wrapParagraph, string rawMarkdown)
 {
     var inlineContent = parser.TokenizeInline(rawMarkdown);
     if (wrapParagraph)
     {
         return new MarkdownParagraphBlockToken(rule, parser.Context, inlineContent, rawMarkdown);
     }
     else
     {
         return new MarkdownNonParagraphBlockToken(rule, parser.Context, inlineContent, rawMarkdown);
     }
 }
Beispiel #5
0
        private static IMarkdownToken CreateToken(IMarkdownParser parser, IMarkdownRule rule, bool wrapParagraph, string rawMarkdown)
        {
            var inlineContent = parser.TokenizeInline(rawMarkdown);

            if (wrapParagraph)
            {
                return(new MarkdownParagraphBlockToken(rule, parser.Context, inlineContent, rawMarkdown));
            }
            else
            {
                return(new MarkdownNonParagraphBlockToken(rule, parser.Context, inlineContent, rawMarkdown));
            }
        }
        public virtual IMarkdownToken TryMatch(IMarkdownParser engine, ref string source)
        {
            var match = Html.Match(source);
            if (match.Length == 0)
            {
                return null;
            }
            source = source.Substring(match.Length);

            bool isPre = engine.Options.Sanitizer == null &&
                (match.Groups[1].Value == "pre" || match.Groups[1].Value == "script" || match.Groups[1].Value == "style");
            if (engine.Options.Sanitize)
            {
                return new MarkdownParagraphBlockToken(this, engine.Context, engine.TokenizeInline(match.Value), match.Value);
            }
            else
            {
                return new MarkdownHtmlBlockToken(
                    this,
                    engine.Context,
                    isPre ? new InlineContent(new IMarkdownToken[] { new MarkdownRawToken(this, engine.Context, match.Value) }.ToImmutableArray()) : engine.TokenizeInline(match.Value),
                    match.Value);
            }
        }
 public virtual IMarkdownToken TryMatch(IMarkdownParser engine, ref string source)
 {
     var match = LHeading.Match(source);
     if (match.Length == 0)
     {
         return null;
     }
     source = source.Substring(match.Length);
     return new MarkdownHeadingBlockToken(
         this,
         engine.Context,
         engine.TokenizeInline(match.Groups[1].Value),
         Regex.Replace(match.Groups[1].Value.ToLower(), @"[^\w]+", "-"),
         match.Groups[2].Value == "=" ? 1 : 2,
         match.Value);
 }
 public virtual IMarkdownToken TryMatch(IMarkdownParser engine, ref string source)
 {
     if (!(bool)engine.Context.Variables[MarkdownBlockContext.IsTop])
     {
         return null;
     }
     var match = Paragraph.Match(source);
     if (match.Length == 0)
     {
         return null;
     }
     source = source.Substring(match.Length);
     var content = match.Groups[1].Value[match.Groups[1].Value.Length - 1] == '\n'
         ? match.Groups[1].Value.Substring(0, match.Groups[1].Value.Length - 1)
         : match.Groups[1].Value;
     return new MarkdownParagraphBlockToken(this, engine.Context, engine.TokenizeInline(content), match.Value);
 }
        public virtual IMarkdownToken TryMatch(IMarkdownParser engine, ref string source)
        {
            var match = Heading.Match(source);

            if (match.Length == 0)
            {
                return(null);
            }
            source = source.Substring(match.Length);
            return(new MarkdownHeadingBlockToken(
                       this,
                       engine.Context,
                       engine.TokenizeInline(match.Groups[2].Value),
                       Regex.Replace(match.Groups[2].Value.ToLower(), @"[^\w]+", "-"),
                       match.Groups[1].Value.Length,
                       match.Value));
        }
Beispiel #10
0
        public virtual IMarkdownToken TryMatch(IMarkdownParser engine, ref string source)
        {
            if (!(bool)engine.Context.Variables[MarkdownBlockContext.IsTop])
            {
                return(null);
            }
            var match = Paragraph.Match(source);

            if (match.Length == 0)
            {
                return(null);
            }
            source = source.Substring(match.Length);
            var content = match.Groups[1].Value[match.Groups[1].Value.Length - 1] == '\n'
                ? match.Groups[1].Value.Substring(0, match.Groups[1].Value.Length - 1)
                : match.Groups[1].Value;

            return(new MarkdownParagraphBlockToken(this, engine.Context, engine.TokenizeInline(content), match.Value));
        }
Beispiel #11
0
 private static TwoPhaseBlockToken CreateTwoPhaseToken(IMarkdownParser parser, IMarkdownRule rule, bool wrapParagraph, SourceInfo sourceInfo)
 {
     var inlineContent = parser.TokenizeInline(sourceInfo);
     if (wrapParagraph)
     {
         return new TwoPhaseBlockToken(
             rule,
             parser.Context,
             sourceInfo,
             (p, t) => new MarkdownParagraphBlockToken(t.Rule, p.Context, p.TokenizeInline(t.SourceInfo), t.SourceInfo));
     }
     else
     {
         return new TwoPhaseBlockToken(
             rule,
             parser.Context,
             sourceInfo,
             (p, t) => new MarkdownNonParagraphBlockToken(t.Rule, p.Context, p.TokenizeInline(t.SourceInfo), t.SourceInfo));
     }
 }
Beispiel #12
0
        private static TwoPhaseBlockToken CreateTwoPhaseToken(IMarkdownParser parser, IMarkdownRule rule, bool wrapParagraph, SourceInfo sourceInfo)
        {
            var inlineContent = parser.TokenizeInline(sourceInfo);

            if (wrapParagraph)
            {
                return(new TwoPhaseBlockToken(
                           rule,
                           parser.Context,
                           sourceInfo,
                           (p, t) => new MarkdownParagraphBlockToken(t.Rule, p.Context, p.TokenizeInline(t.SourceInfo), t.SourceInfo)));
            }
            else
            {
                return(new TwoPhaseBlockToken(
                           rule,
                           parser.Context,
                           sourceInfo,
                           (p, t) => new MarkdownNonParagraphBlockToken(t.Rule, p.Context, p.TokenizeInline(t.SourceInfo), t.SourceInfo)));
            }
        }