// process the match
        public IMarkdownToken TryMatch(IMarkdownParser parser, IMarkdownParsingContext context)
        {
            // TODO: This does not process this token from within a code block like

            // ```
            // dotnet tool install lucene-cli -g --version [EnvVar: LuceneNetVersion]
            // ```

            var match = _envVarRegex.Match(context.CurrentMarkdown);

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

            var envVar = match.Groups[1].Value;
            var text   = Environment.GetEnvironmentVariable(envVar);

            if (text == null)
            {
                return(null);
            }

            // 'eat' the characters of the current markdown token so they anr
            var sourceInfo = context.Consume(match.Length);

            return(new MarkdownTextToken(this, parser.Context, text, sourceInfo));
        }
示例#2
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 TwoPhaseBlockToken(this, engine.Context, match.Value, (p, t) =>
                    new MarkdownParagraphBlockToken(t.Rule, t.Context, p.TokenizeInline(match.Value), t.RawMarkdown));
            }
            else
            {
                return new TwoPhaseBlockToken(this, engine.Context, match.Value, (p, t) =>
                    new MarkdownHtmlBlockToken(
                        t.Rule,
                        t.Context,
                        isPre ? new InlineContent(new IMarkdownToken[] { new MarkdownRawToken(this, engine.Context, t.RawMarkdown) }.ToImmutableArray()) : p.TokenizeInline(t.RawMarkdown),
                        t.RawMarkdown));
            }
        }
        public virtual IMarkdownToken TryMatch(IMarkdownParser parser, IMarkdownParsingContext context)
        {
            var match = NpTable.Match(context.CurrentMarkdown);

            if (match.Length == 0)
            {
                return(null);
            }
            var sourceInfo = context.Consume(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 TwoPhaseBlockToken(
                       this,
                       parser.Context,
                       sourceInfo,
                       (p, t) => new MarkdownTableBlockToken(
                           t.Rule,
                           t.Context,
                           (from text in header
                            let si = t.SourceInfo.Copy(text)
                                     select new MarkdownTableItemBlockToken(t.Rule, t.Context, p.TokenizeInline(si), si)).ToImmutableArray(),
                           align.ToImmutableArray(),
                           (from row in cells
                            select(from col in row
                                   let si = t.SourceInfo.Copy(col)
                                            select new MarkdownTableItemBlockToken(t.Rule, t.Context, p.TokenizeInline(si), si)).ToImmutableArray()).ToImmutableArray(),
                           t.SourceInfo)));
        }
示例#4
0
 public override IMarkdownToken TryMatch(IMarkdownParser parser, IMarkdownParsingContext context)
 {
     var c = parser.SwitchContext(MarkdownBlockContext.IsBlockQuote, true);
     var result = base.TryMatch(parser, context);
     parser.SwitchContext(c);
     return result;
 }
        public virtual IMarkdownToken TryMatch(IMarkdownParser engine, IMarkdownParsingContext context)
        {
            var match = AzureHtmlMetadataRegex.Match(context.CurrentMarkdown);

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

            var    sourceInfo = context.Consume(match.Length);
            object currentFilePath;

            if (!engine.Context.Variables.TryGetValue("path", out currentFilePath))
            {
                Logger.LogWarning($"Can't get path for setting azure ms.assetid. Won't set it.");
                currentFilePath = string.Empty;
            }

            var metadata = GetAttributesFromHtmlContent(match.Value);

            if (metadata == null)
            {
                return(new MarkdownTextToken(this, engine.Context, match.Value, sourceInfo));
            }
            return(new AzureHtmlMetadataBlockToken(this, engine.Context, metadata.Properties, metadata.Tags, sourceInfo));
        }
示例#6
0
        public virtual IMarkdownToken TryMatch(IMarkdownParser engine, ref string source)
        {
            if ((bool)engine.Context.Variables[MarkdownInlineContext.IsInLink])
            {
                return null;
            }
            var match = Url.Match(source);
            if (match.Length == 0)
            {
                return null;
            }
            var text = StringHelper.Escape(match.Groups[1].Value);
            if (!Uri.IsWellFormedUriString(text, UriKind.RelativeOrAbsolute))
            {
                return null;
            }

            source = source.Substring(match.Length);
            return new MarkdownLinkInlineToken(
                this,
                engine.Context,
                text,
                null,
                ImmutableArray<IMarkdownToken>.Empty.Add(
                    new MarkdownRawToken(this, engine.Context, text)),
                match.Value);
        }
示例#7
0
        public IMarkdownToken TryMatch(IMarkdownParser parser, IMarkdownParsingContext context)
        {
            var match = YamlHeader.Match(context.CurrentMarkdown);
            if (match.Length == 0)
            {
                return null;
            }

            // ---
            // a: b
            // ---
            var value = match.Groups[1].Value;
            try
            {
                using (StringReader reader = new StringReader(value))
                {
                    var result = YamlUtility.Deserialize<Dictionary<string, object>>(reader);
                    if (result == null)
                    {
                        return null;
                    }
                }
            }
            catch (Exception)
            {
                return null;
            }
            var sourceInfo = context.Consume(match.Length);
            return new DfmYamlHeaderBlockToken(this, parser.Context, value, sourceInfo);
        }
        public IMarkdownToken TryMatch(IMarkdownParser engine, ref string source)
        {
            var match = YamlHeader.Match(source);

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

            // ---
            // a: b
            // ---
            var value = match.Groups[1].Value;

            try
            {
                using (StringReader reader = new StringReader(value))
                    YamlUtility.Deserialize <Dictionary <string, object> >(reader);
            }
            catch (Exception)
            {
                return(null);
            }

            source = source.Substring(match.Length);
            return(new DfmYamlHeaderBlockToken(this, engine.Context, value, match.Value));
        }
示例#9
0
        public virtual IMarkdownToken TryMatch(IMarkdownParser parser, IMarkdownParsingContext context)
        {
            if (!(bool)parser.Context.Variables[MarkdownBlockContext.IsTop])
            {
                return(null);
            }
            var match = Paragraph.Match(context.CurrentMarkdown);

            if (match.Length == 0)
            {
                return(null);
            }
            var sourceInfo = context.Consume(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 TwoPhaseBlockToken(
                       this,
                       parser.Context,
                       sourceInfo,
                       (p, t) => new MarkdownParagraphBlockToken(
                           t.Rule,
                           t.Context,
                           p.TokenizeInline(t.SourceInfo.Copy(content)),
                           t.SourceInfo)));
        }
示例#10
0
        public override IMarkdownToken TryMatch(IMarkdownParser parser, IMarkdownParsingContext context)
        {
            if (parser.Options.LegacyMode)
            {
                return(TryMatchOld(parser, context));
            }
            var match = context.Match(DfmFencesMatcher);

            if (match?.Length > 0)
            {
                var sourceInfo = context.Consume(match.Length);

                // [!code-lang[name](href "optionalTitle")]
                var name  = StringHelper.UnescapeMarkdown(match["name"].GetValue());
                var href  = StringHelper.UnescapeMarkdown(match["href"].GetValue());
                var lang  = match.GetGroup("lang")?.GetValue() ?? string.Empty;
                var title = StringHelper.UnescapeMarkdown(match.GetGroup("title")?.GetValue() ?? string.Empty);
                var queryStringAndFragment = UriUtility.GetQueryStringAndFragment(href);
                var path            = UriUtility.GetPath(href);
                var pathQueryOption =
                    !string.IsNullOrEmpty(queryStringAndFragment) ?
                    ParsePathQueryString(queryStringAndFragment.Remove(1), queryStringAndFragment.Substring(1)) :
                    null;
                return(new DfmFencesBlockToken(this, parser.Context, name, path, sourceInfo, lang, title, pathQueryOption, queryStringAndFragment));
            }
            return(null);
        }
示例#11
0
 public IMarkdownToken Extract(IMarkdownParser parser)
 {
     var c = parser.SwitchContext(Context);
     var result = _extractor(parser, this);
     parser.SwitchContext(c);
     return result;
 }
        public virtual IMarkdownToken TryMatch(IMarkdownParser engine, ref string source)
        {
            var match = AutoLink.Match(source);
            if (match.Length == 0)
            {
                return null;
            }
            source = source.Substring(match.Length);

            StringBuffer text;
            StringBuffer href;
            if (match.Groups[2].Value == "@")
            {
                text = match.Groups[1].Value[6] == ':'
                  ? Mangle(engine.Options.Mangle, match.Groups[1].Value.Substring(7))
                  : Mangle(engine.Options.Mangle, match.Groups[1].Value);
                href = Mangle(engine.Options.Mangle, "mailto:") + text;
            }
            else
            {
                text = StringHelper.Escape(match.Groups[1].Value);
                href = text;
            }

            return new MarkdownLinkInlineToken(
                this, 
                engine.Context, 
                href, 
                null, 
                ImmutableArray<IMarkdownToken>.Empty.Add(
                    new MarkdownRawToken(this, engine.Context, text)),
                match.Value);
        }
示例#13
0
        public IMarkdownToken TryMatch(IMarkdownParser parser, IMarkdownParsingContext context)
        {
            if (Include != _incRegex || parser.Options.LegacyMode)
            {
                return(TryMatchOld(parser, context));
            }
            var match = context.Match(IncludeMatcher);

            if (match?.Length > 0)
            {
                var sourceInfo = context.Consume(match.Length);

                // [!include[name](path "title")]
                var path  = match["path"].GetValue();
                var name  = match["name"].GetValue();
                var title = match.GetGroup("title")?.GetValue() ?? string.Empty;

                return(new DfmIncludeBlockToken(
                           this,
                           parser.Context,
                           StringHelper.UnescapeMarkdown(path),
                           StringHelper.UnescapeMarkdown(name),
                           StringHelper.UnescapeMarkdown(title),
                           sourceInfo));
            }
            return(null);
        }
示例#14
0
        public virtual IMarkdownToken TryMatch(IMarkdownParser parser, IMarkdownParsingContext context)
        {
            if (LHeading != Regexes.Block.LHeading)
            {
                return(TryMatchOld(parser, context));
            }
            var match = context.Match(LHeadingMatcher);

            if (match?.Length > 0)
            {
                var sourceInfo = context.Consume(match.Length);
                return(new TwoPhaseBlockToken(
                           this,
                           parser.Context,
                           sourceInfo,
                           (p, t) => new MarkdownHeadingBlockToken(
                               t.Rule,
                               t.Context,
                               p.TokenizeInline(t.SourceInfo.Copy(match["text"].GetValue())),
                               Regex.Replace(match["text"].GetValue().ToLower(), @"[^\p{L}\p{N}\- ]+", "").Replace(' ', '-'),
                               context.Markdown[match["level"].StartIndex] == '=' ? 1 : 2,
                               t.SourceInfo)));
            }
            return(null);
        }
示例#15
0
        public virtual IMarkdownToken TryMatch(IMarkdownParser engine, ref string source)
        {
            var match = AzureHtmlMetadataRegex.Match(source);

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

            source = source.Substring(match.Length);

            object currentFilePath;

            if (!engine.Context.Variables.TryGetValue("path", out currentFilePath))
            {
                Logger.LogWarning($"Can't get path for setting azure ms.assetid. Won't set it.");
                currentFilePath = string.Empty;
            }

            var metadata = GetAttributesFromHtmlContent(match.Value);

            metadata.Properties["ms.assetid"] = $"{AzureDocumentPrefix}/{Path.GetFileNameWithoutExtension(currentFilePath.ToString())}";
            if (metadata == null)
            {
                return(new MarkdownTextToken(this, engine.Context, match.Value, match.Value));
            }
            return(new AzureHtmlMetadataBlockToken(this, engine.Context, metadata.Properties, metadata.Tags, match.Value));
        }
示例#16
0
        public IMarkdownToken TryMatch(IMarkdownParser parser, IMarkdownParsingContext context)
        {
            if (MarkdownInlineContext.GetIsInLink(parser.Context))
            {
                return(null);
            }
            var match = XrefShortcutRegexWithQuote.Match(context.CurrentMarkdown);

            if (match.Length == 0)
            {
                match = XrefShortcutRegex.Match(context.CurrentMarkdown);
                if (match.Length == 0)
                {
                    return(null);
                }
            }

            var sourceInfo = context.Consume(match.Length);

            // @String=>cap[2]=String, @'string'=>cap[2]=string
            // For cross-reference, add ~/ prefix
            var content = match.Groups[2].Value;

            return(new DfmXrefInlineToken(this, parser.Context, content, ImmutableArray <IMarkdownToken> .Empty, null, false, sourceInfo));
        }
示例#17
0
        public virtual IMarkdownToken TryMatch(IMarkdownParser parser, IMarkdownParsingContext context)
        {
            if (context.IsInParagraph)
            {
                return(null);
            }
            if (Code != Regexes.Block.Code)
            {
                return(TryMatchOld(parser, context));
            }
            var match = context.Match(CodeMatcher);

            if (match?.Length > 0)
            {
                var sourceInfo = context.Consume(match.Length);
                var capStr     = Regexes.Lexers.LeadingWhiteSpaces.Replace(sourceInfo.Markdown, string.Empty);
                if (parser.Options.Pedantic)
                {
                    return(new MarkdownCodeBlockToken(this, parser.Context, capStr, null, sourceInfo));
                }
                else
                {
                    return(new MarkdownCodeBlockToken(this, parser.Context, Regexes.Lexers.TailingEmptyLines.Replace(capStr, string.Empty), null, sourceInfo));
                }
            }
            return(null);
        }
示例#18
0
        public virtual IMarkdownToken TryMatch(IMarkdownParser parser, ref string source)
        {
            var match = Html.Match(source);

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

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

            if (parser.Options.Sanitize)
            {
                return(new TwoPhaseBlockToken(this, parser.Context, match.Value, (p, t) =>
                                              new MarkdownParagraphBlockToken(t.Rule, t.Context, p.TokenizeInline(match.Value), t.RawMarkdown)));
            }
            else
            {
                return(new TwoPhaseBlockToken(this, parser.Context, match.Value, (p, t) =>
                                              new MarkdownHtmlBlockToken(
                                                  t.Rule,
                                                  t.Context,
                                                  isPre ? new InlineContent(new IMarkdownToken[] { new MarkdownRawToken(this, parser.Context, t.RawMarkdown) }.ToImmutableArray()) : p.TokenizeInline(t.RawMarkdown),
                                                  t.RawMarkdown)));
            }
        }
示例#19
0
        public virtual IMarkdownToken TryMatch(IMarkdownParser parser, IMarkdownParsingContext context)
        {
            var match = AutoLink.Match(context.CurrentMarkdown);
            if (match.Length == 0)
            {
                return null;
            }
            var sourceInfo = context.Consume(match.Length);

            StringBuffer text;
            StringBuffer href;
            if (match.Groups[2].Value == "@")
            {
                text = match.Groups[1].Value[6] == ':'
                  ? Mangle(parser.Options.Mangle, match.Groups[1].Value.Substring(7))
                  : Mangle(parser.Options.Mangle, match.Groups[1].Value);
                href = Mangle(parser.Options.Mangle, "mailto:") + text;
            }
            else
            {
                text = StringHelper.Escape(match.Groups[1].Value);
                href = match.Groups[1].Value;
            }

            return new MarkdownLinkInlineToken(
                this, 
                parser.Context, 
                href, 
                null, 
                ImmutableArray.Create<IMarkdownToken>(
                    new MarkdownRawToken(this, parser.Context, sourceInfo.Copy(text))),
                sourceInfo,
                MarkdownLinkType.AutoLink,
                null);
        }
示例#20
0
        public virtual IMarkdownToken TryMatch(IMarkdownParser parser, IMarkdownParsingContext context)
        {
            if ((bool)parser.Context.Variables[MarkdownInlineContext.IsInLink])
            {
                return(null);
            }
            var match = Url.Match(context.CurrentMarkdown);

            if (match.Length == 0)
            {
                return(null);
            }
            var text = StringHelper.Escape(match.Groups[1].Value);

            if (!Uri.IsWellFormedUriString(text, UriKind.RelativeOrAbsolute))
            {
                return(null);
            }

            var sourceInfo = context.Consume(match.Length);

            return(new MarkdownLinkInlineToken(
                       this,
                       parser.Context,
                       text,
                       null,
                       ImmutableArray.Create <IMarkdownToken>(
                           new MarkdownRawToken(this, parser.Context, sourceInfo.Copy(match.Groups[1].Value))),
                       sourceInfo,
                       MarkdownLinkType.UrlLink,
                       null));
        }
示例#21
0
        public virtual IMarkdownToken TryMatch(IMarkdownParser parser, 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 TwoPhaseBlockToken(this, parser.Context, match.Value, (p, t) =>
                                          new MarkdownTableBlockToken(
                                              t.Rule,
                                              t.Context,
                                              (from text in header
                                               select p.TokenizeInline(text)).ToImmutableArray(),
                                              align.ToImmutableArray(),
                                              (from row in cells
                                               select(from col in row
                                                      select p.TokenizeInline(col)).ToImmutableArray()).ToImmutableArray())));
        }
示例#22
0
        public virtual IMarkdownToken TryMatch(IMarkdownParser parser, IMarkdownParsingContext context)
        {
            if ((bool)parser.Context.Variables[MarkdownInlineContext.IsInLink])
            {
                return null;
            }
            var match = Url.Match(context.CurrentMarkdown);
            if (match.Length == 0)
            {
                return null;
            }
            var text = StringHelper.Escape(match.Groups[1].Value);
            if (!Uri.IsWellFormedUriString(text, UriKind.RelativeOrAbsolute))
            {
                return null;
            }

            var sourceInfo = context.Consume(match.Length);
            return new MarkdownLinkInlineToken(
                this,
                parser.Context,
                text,
                null,
                ImmutableArray.Create<IMarkdownToken>(
                    new MarkdownRawToken(this, parser.Context, sourceInfo.Copy(match.Groups[1].Value))),
                sourceInfo,
                MarkdownLinkType.UrlLink,
                null);
        }
        public override IMarkdownToken TryMatch(IMarkdownParser parser, IMarkdownParsingContext context)
        {
            var match = RefLink.Match(context.CurrentMarkdown);

            if (match.Length == 0)
            {
                return(null);
            }
            if (MarkdownInlineContext.GetIsInLink(parser.Context) && match.Value[0] != '!')
            {
                return(null);
            }

            var linkStr = match.NotEmpty(2, 1).ReplaceRegex(Regexes.Lexers.WhiteSpaces, " ");

            LinkObj link;

            parser.Links.TryGetValue(linkStr.ToLower(), out link);

            if (string.IsNullOrEmpty(link?.Href))
            {
                var sourceInfo = context.Consume(1);
                var text       = match.Value.Remove(1);
                return(new MarkdownTextToken(this, parser.Context, text, sourceInfo));
            }
            else
            {
                var sourceInfo = context.Consume(match.Length);
                return(GenerateToken(parser, link.Href, link.Title, match.Groups[1].Value, match.Value[0] == '!', sourceInfo, MarkdownLinkType.RefLink, linkStr));
            }
        }
示例#24
0
        public override IMarkdownToken TryMatch(IMarkdownParser parser, IMarkdownParsingContext context)
        {
            var match = RefLink.Match(context.CurrentMarkdown);
            if (match.Length == 0)
            {
                return null;
            }

            var linkStr = match.NotEmpty(2, 1).ReplaceRegex(Regexes.Lexers.WhiteSpaces, " ");

            LinkObj link;
            parser.Links.TryGetValue(linkStr.ToLower(), out link);

            if (string.IsNullOrEmpty(link?.Href))
            {
                var sourceInfo = context.Consume(1);
                var text = match.Value.Remove(1);
                return new MarkdownTextToken(this, parser.Context, text, sourceInfo);
            }
            else
            {
                var sourceInfo = context.Consume(match.Length);
                return GenerateToken(parser, link.Href, link.Title, match.Groups[1].Value, match.Value[0] == '!', sourceInfo, MarkdownLinkType.RefLink, linkStr);
            }
        }
示例#25
0
        public override IMarkdownToken TryMatch(IMarkdownParser parser, IMarkdownParsingContext context)
        {
            if (!parser.Context.GetIsInTable())
            {
                if (!parser.Options.LegacyMode)
                {
                    return(null);
                }
            }
            var match = _dfmFencesRegex.Match(context.CurrentMarkdown);

            if (match.Length == 0)
            {
                return(null);
            }
            var sourceInfo = context.Consume(match.Length);

            // [!code-REST-i[name](path "optionalTitle")]
            var name            = match.Groups["name"].Value;
            var path            = match.Groups["path"].Value;
            var lang            = match.Groups["lang"]?.Value;
            var title           = match.Groups["title"]?.Value;
            var pathQueryOption = ParsePathQueryString(match.Groups["option"]?.Value, match.Groups["optionValue"]?.Value);

            if (!parser.Context.GetIsInTable())
            {
                Logger.LogWarning("Inline code snippet is only allowed inside tables.", line: sourceInfo.LineNumber.ToString(), code: WarningCodes.Markdown.InvalidInlineCodeSnippet);
            }
            return(new DfmFencesBlockToken(this, parser.Context, name, path, sourceInfo, lang, title, pathQueryOption));
        }
示例#26
0
 public override IMarkdownToken TryMatch(IMarkdownParser engine, ref string source)
 {
     var c = engine.SwitchContext(MarkdownBlockContext.IsBlockQuote, true);
     var result = base.TryMatch(engine, ref source);
     engine.SwitchContext(c);
     return result;
 }
示例#27
0
        public IMarkdownToken TryMatch(IMarkdownParser engine, ref string source)
        {
            var match = YamlHeader.Match(source);
            if (match.Length == 0)
            {
                return null;
            }

            // ---
            // a: b
            // ---
            var value = match.Groups[1].Value;
            try
            {
                using (StringReader reader = new StringReader(value))
                    YamlUtility.Deserialize<Dictionary<string, object>>(reader);
            }
            catch (Exception)
            {
                return null;
            }

            source = source.Substring(match.Length);
            return new DfmYamlHeaderBlockToken(this, engine.Context, value, match.Value);
        }
示例#28
0
 public virtual IMarkdownToken TryMatch(IMarkdownParser engine, ref string source)
 {
     var match = Table.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.UselessGfmTableCell, string.Empty).Split('\n').Select(x => new string[] { x }).ToArray();
     for (int i = 0; i < cells.Length; i++)
     {
         cells[i] = cells[i][0]
           .ReplaceRegex(Regexes.Lexers.EmptyGfmTableCell, string.Empty)
           .SplitRegex(Regexes.Lexers.TableSplitter);
     }
     return new TwoPhaseBlockToken(this, engine.Context, match.Value, (p, t) =>
             new MarkdownTableBlockToken(
                 t.Rule,
                 t.Context,
                 (from text in header
                  select p.TokenizeInline(text)).ToImmutableArray(),
                 align.ToImmutableArray(),
                 (from row in cells
                  select (from col in row
                          select p.TokenizeInline(col)).ToImmutableArray()).ToImmutableArray()));
 }
示例#29
0
        public override IMarkdownToken TryMatch(IMarkdownParser parser, ref string source)
        {
            var c      = parser.SwitchContext(MarkdownBlockContext.IsBlockQuote, true);
            var result = base.TryMatch(parser, ref source);

            parser.SwitchContext(c);
            return(result);
        }
示例#30
0
        public IMarkdownToken Extract(IMarkdownParser parser)
        {
            var c      = parser.SwitchContext(Context);
            var result = _extractor(parser, this);

            parser.SwitchContext(c);
            return(result);
        }
示例#31
0
 public IMarkdownParser GetParser()
 {
     if (_currentParser != null)
     {
         return(_currentParser);
     }
     _currentParser = new MarkdownParserMarkdig(false, null);
     return(_currentParser);
 }
示例#32
0
 private static IMarkdownToken GroupTextTokens(IMarkdownParser parser, IMarkdownRule rule, bool wrapParagraph, StringBuffer textContent, SourceInfo si)
 {
     if (textContent.EndsWith('\n'))
     {
         textContent = textContent.Substring(0, textContent.GetLength() - 1);
     }
     var rawMarkdown = textContent.ToString();
     return CreateTwoPhaseToken(parser, rule, wrapParagraph, si.Copy(rawMarkdown));
 }
示例#33
0
 public GenerateHandler(GenerateOptions options,
                        ILog log,
                        IEnvironmentAbstraction environment,
                        IFileSystem fileSystem,
                        IGitHubClient gitHubClient,
                        IMarkdownParser markdownParser) : base(options, log, environment, fileSystem, gitHubClient,
                                                               markdownParser)
 {
 }
 public virtual IMarkdownToken TryMatch(IMarkdownParser engine, ref string source)
 {
     var match = Escape.Match(source);
     if (match.Length == 0)
     {
         return null;
     }
     source = source.Substring(match.Length);
     return new MarkdownEscapeInlineToken(this, engine.Context, match.Groups[1].Value, match.Value);
 }
 public virtual IMarkdownToken TryMatch(IMarkdownParser parser, IMarkdownParsingContext context)
 {
     var match = EscapedText.Match(context.CurrentMarkdown);
     if (match.Length == 0)
     {
         return null;
     }
     var sourceInfo = context.Consume(match.Length);
     return new MarkdownTextToken(this, parser.Context, StringHelper.Escape(match.Groups[1].Value), sourceInfo);
 }
示例#36
0
 public virtual IMarkdownToken TryMatch(IMarkdownParser parser, IMarkdownParsingContext context)
 {
     var match = Del.Match(context.CurrentMarkdown);
     if (match.Length == 0)
     {
         return null;
     }
     var sourceInfo = context.Consume(match.Length);
     return new GfmDelInlineToken(this, parser.Context, parser.Tokenize(sourceInfo.Copy(match.Groups[1].Value)), sourceInfo);
 }
示例#37
0
 public IMarkdownToken TryMatch(IMarkdownParser engine, ref string source)
 {
     var match = Xref.Match(source);
     if (match.Length == 0)
     {
         return null;
     }
     source = source.Substring(match.Length);
     return new MarkdownTextToken(this, engine.Context, match.Groups[0].Value, match.Value);
 }
示例#38
0
        private static IMarkdownToken GroupTextTokens(IMarkdownParser parser, IMarkdownRule rule, bool wrapParagraph, StringBuffer textContent, SourceInfo si)
        {
            if (textContent.EndsWith('\n'))
            {
                textContent = textContent.Substring(0, textContent.GetLength() - 1);
            }
            var rawMarkdown = textContent.ToString();

            return(CreateTwoPhaseToken(parser, rule, wrapParagraph, si.Copy(rawMarkdown)));
        }
示例#39
0
 public IMarkdownToken TryMatch(IMarkdownParser parser, IMarkdownParsingContext context)
 {
     var match = Fences.Match(context.CurrentMarkdown);
     if (match.Length == 0)
     {
         return null;
     }
     var sourceInfo = context.Consume(match.Length);
     return new MarkdownCodeBlockToken(this, parser.Context, match.Groups[3].Value, match.Groups[2].Value, sourceInfo);
 }
 public virtual IMarkdownToken TryMatch(IMarkdownParser engine, ref string source)
 {
     var match = Newline.Match(source);
     if (match.Length == 0)
     {
         return null;
     }
     source = source.Substring(match.Length);
     return new MarkdownNewLineBlockToken(this, engine.Context, match.Value);
 }
示例#41
0
        public virtual IMarkdownToken TryMatch(IMarkdownParser parser, IMarkdownParsingContext context)
        {
            var match = context.Match(_sdnsMatcher);

            return(match?.Length > 0 ? new SDNSBlockToken(
                       this,
                       parser.Context,
                       context.Consume(match.Length),
                       match.GetGroup("text").Value.GetValue()) : null);
        }
示例#42
0
 public virtual IMarkdownToken TryMatch(IMarkdownParser parser, IMarkdownParsingContext context)
 {
     var match = Em.Match(context.CurrentMarkdown);
     if (match.Length == 0)
     {
         return null;
     }
     var sourceInfo = context.Consume(match.Length);
     return new MarkdownEmInlineToken(this, parser.Context, parser.Tokenize(sourceInfo.Copy(match.NotEmpty(2, 1))), sourceInfo);
 }
示例#43
0
 public virtual IMarkdownToken TryMatch(IMarkdownParser parser, IMarkdownParsingContext context)
 {
     var match = Br.Match(context.CurrentMarkdown);
     if (match.Length == 0)
     {
         return null;
     }
     var sourceInfo = context.Consume(match.Length);
     return new MarkdownBrInlineToken(this, parser.Context, sourceInfo);
 }
示例#44
0
        public override IMarkdownToken TryMatch(IMarkdownParser parser, IMarkdownParsingContext context)
        {
            var token = base.TryMatch(parser, context);

            if (token is TwoPhaseBlockToken tp)
            {
                return(new TwoPhaseBlockToken(tp, tp.Context.SetIsInTable()));
            }
            return(token);
        }
示例#45
0
        public virtual IMarkdownToken TryMatch(IMarkdownParser parser, IMarkdownParsingContext context)
        {
            if (context.IsInParagraph)
            {
                return(null);
            }
            if (Html != Regexes.Block.Html)
            {
                return(TryMatchOld(parser, context));
            }
            var match = context.Match(HtmlMatcher);

            if (match?.Length > 0)
            {
                var sourceInfo = context.Consume(match.Length);

                var  elementName = match.GetGroup("element")?.GetValue();
                bool isPre       = parser.Options.Sanitizer == null &&
                                   ("pre".Equals(elementName, StringComparison.OrdinalIgnoreCase) || "script".Equals(elementName, StringComparison.OrdinalIgnoreCase) || "style".Equals(elementName, StringComparison.OrdinalIgnoreCase));
                if (parser.Options.Sanitize)
                {
                    return(new TwoPhaseBlockToken(
                               this,
                               parser.Context,
                               sourceInfo,
                               (p, t) => new MarkdownParagraphBlockToken(
                                   t.Rule,
                                   t.Context,
                                   p.TokenizeInline(t.SourceInfo),
                                   t.SourceInfo)));
                }
                else
                {
                    return(new TwoPhaseBlockToken(
                               this,
                               parser.Context,
                               sourceInfo,
                               (p, t) => new MarkdownHtmlBlockToken(
                                   t.Rule,
                                   t.Context,
                                   isPre ?
                                   new InlineContent(
                                       ImmutableArray.Create <IMarkdownToken>(
                                           new MarkdownRawToken(
                                               this,
                                               parser.Context,
                                               t.SourceInfo)))
                            :
                                   p.TokenizeInline(t.SourceInfo),
                                   t.SourceInfo)));
                }
            }
            return(null);
        }
示例#46
0
        public override IMarkdownToken TryMatch(IMarkdownParser engine, ref string source)
        {
            var match = Link.Match(source);
            if (match.Length == 0)
            {
                return null;
            }
            source = source.Substring(match.Length);

            return GenerateToken(engine, match.Groups[2].Value, match.Groups[3].Value, match.Groups[1].Value, match.Value[0] == '!', match.Value);
        }
示例#47
0
        public virtual IMarkdownToken TryMatch(IMarkdownParser engine, ref string source)
        {
            var match = Strong.Match(source);
            if (match.Length == 0)
            {
                return null;
            }
            source = source.Substring(match.Length);

            return new MarkdownStrongInlineToken(this, engine.Context, engine.Tokenize(match.NotEmpty(2, 1)), match.Value);
        }
        public virtual IMarkdownToken TryMatch(IMarkdownParser engine, ref string source)
        {
            var match = Escape.Match(source);

            if (match.Length == 0)
            {
                return(null);
            }
            source = source.Substring(match.Length);
            return(new MarkdownEscapeInlineToken(this, engine.Context, match.Groups[1].Value, match.Value));
        }
示例#49
0
        public IMarkdownToken TryMatch(IMarkdownParser engine, ref string source)
        {
            var match = Xref.Match(source);

            if (match.Length == 0)
            {
                return(null);
            }
            source = source.Substring(match.Length);
            return(new MarkdownTextToken(this, engine.Context, match.Groups[0].Value, match.Value));
        }
示例#50
0
        public virtual IMarkdownToken TryMatch(IMarkdownParser engine, ref string source)
        {
            var match = Newline.Match(source);

            if (match.Length == 0)
            {
                return(null);
            }
            source = source.Substring(match.Length);
            return(new MarkdownNewLineBlockToken(this, engine.Context, match.Value));
        }
示例#51
0
        public virtual IMarkdownToken TryMatch(IMarkdownParser engine, ref string source)
        {
            var match = Del.Match(source);
            if (match.Length == 0)
            {
                return null;
            }
            source = source.Substring(match.Length);

            return new GfmDelInlineToken(this, engine.Context, engine.Tokenize(match.Groups[1].Value), match.Value);
        }
示例#52
0
        public virtual IMarkdownToken TryMatch(IMarkdownParser engine, ref string source)
        {
            var match = Text.Match(source);
            if (match.Length == 0)
            {
                return null;
            }
            source = source.Substring(match.Length);

            return new MarkdownTextToken(this, engine.Context, StringHelper.Escape(Smartypants(engine.Options, match.Groups[0].Value)), match.Value);
        }
示例#53
0
        public IMarkdownToken TryMatch(IMarkdownParser parser, IMarkdownParsingContext context)
        {
            var match = context.Match(_FencesMatcher);

            if (match?.Length > 0)
            {
                var sourceInfo = context.Consume(match.Length);
                return(new MarkdownCodeBlockToken(this, parser.Context, match["code"].GetValue(), match["lang"].GetValue(), sourceInfo));
            }
            return(null);
        }
示例#54
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);
     }
 }
示例#55
0
 protected virtual IMarkdownToken GenerateToken(IMarkdownParser parser, string href, string title, string text, bool isImage, SourceInfo sourceInfo, MarkdownLinkType linkType, string refId)
 {
     var escapedHref = Regexes.Helper.MarkdownEscape.Replace(href, m => m.Groups[1].Value);
     if (isImage)
     {
         return new MarkdownImageInlineToken(this, parser.Context, escapedHref, title, text, sourceInfo, linkType, refId);
     }
     else
     {
         return new MarkdownLinkInlineToken(this, parser.Context, escapedHref, title, parser.Tokenize(sourceInfo.Copy(text)), sourceInfo, linkType, refId);
     }
 }
 protected virtual IMarkdownToken GenerateToken(IMarkdownParser engine, string href, string title, string text, bool isImage, string rawMarkdown)
 {
     var escapedHref = StringHelper.Escape(href);
     var escapedTitle = !string.IsNullOrEmpty(title) ? StringHelper.Escape(title) : null;
     if (isImage)
     {
         return new MarkdownImageInlineToken(this, engine.Context, escapedHref, escapedTitle, text, rawMarkdown);
     }
     else
     {
         return new MarkdownLinkInlineToken(this, engine.Context, escapedHref, escapedTitle, engine.Tokenize(text), rawMarkdown);
     }
 }
 public virtual IMarkdownToken TryMatch(IMarkdownParser engine, ref string source)
 {
     var match = Blockquote.Match(source);
     if (match.Length == 0)
     {
         return null;
     }
     source = source.Substring(match.Length);
     var capStr = LeadingBlockquote.Replace(match.Value, string.Empty);
     var blockTokens = engine.Tokenize(capStr);
     blockTokens = TokenHelper.ParseInlineToken(engine, this, blockTokens, true);
     return new MarkdownBlockquoteBlockToken(this, engine.Context, blockTokens, match.Value);
 }
 public override IMarkdownToken TryMatch(IMarkdownParser engine, ref string source)
 {
     var match = Blockquote.Match(source);
     if (match.Length == 0)
     {
         return null;
     }
     source = source.Substring(match.Length);
     var capStr = LeadingBlockquote.Replace(match.Value, string.Empty);
     var c = engine.SwitchContext(MarkdownBlockContext.IsBlockQuote, true);
     var tokens = engine.Tokenize(capStr);
     engine.SwitchContext(c);
     return new AzureBlockquoteBlockToken(this, engine.Context, tokens, match.Value);
 }
示例#59
0
 public virtual IMarkdownToken TryMatch(IMarkdownParser engine, IMarkdownParsingContext context)
 {
     if (!engine.Context.Variables.ContainsKey(MarkdownBlockContext.IsBlockQuote) || !(bool)engine.Context.Variables[MarkdownBlockContext.IsBlockQuote])
     {
         return null;
     }
     var match = AzureNoteRegex.Match(context.CurrentMarkdown);
     if (match.Length == 0)
     {
         return null;
     }
     var sourceInfo = context.Consume(match.Groups["rawmarkdown"].Length);
     return new AzureNoteBlockToken(this, engine.Context, match.Groups["notetype"].Value, match.Groups["rawmarkdown"].Value, sourceInfo);
 }