Inheritance: ICloneable
Example #1
0
        public virtual IMarkdownToken TryMatch(MarkdownEngine 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, href, null, text));
        }
Example #2
0
        public virtual StringBuffer Render(MarkdownEngine engine, MarkdownListItemBlockToken token, MarkdownBlockContext context)
        {
            StringBuffer content = "<li>";

            content += RenderTokens(engine, token.Tokens, context, token.Loose, token.Rule);
            return(content + "</li>\n");
        }
Example #3
0
        public virtual StringBuffer Render(MarkdownEngine engine, MarkdownCodeBlockToken token, MarkdownBlockContext context)
        {
            bool escaped = false;
            string code = token.Code;
            if (engine.Options.Highlight != null)
            {
                var highlightCode = engine.Options.Highlight(code, token.Lang);
                if (highlightCode != null && highlightCode != code)
                {
                    escaped = true;
                    code = highlightCode;
                }
            }

            if (string.IsNullOrEmpty(token.Lang))
            {
                return (StringBuffer)"<pre><code>" + (escaped ? code : StringHelper.Escape(code, true)) + "\n</code></pre>";
            }

            return "<pre><code class=\""
                + engine.Options.LangPrefix
                + StringHelper.Escape(token.Lang, true)
                + "\">"
                + (escaped ? code : StringHelper.Escape(code, true))
                + "\n</code></pre>\n";
        }
        public virtual IMarkdownToken TryMatch(MarkdownEngine 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, href, null, text);
        }
Example #5
0
        public virtual StringBuffer Render(MarkdownEngine engine, MarkdownCodeBlockToken token, MarkdownBlockContext context)
        {
            bool   escaped = false;
            string code    = token.Code;

            if (engine.Options.Highlight != null)
            {
                var highlightCode = engine.Options.Highlight(code, token.Lang);
                if (highlightCode != null && highlightCode != code)
                {
                    escaped = true;
                    code    = highlightCode;
                }
            }

            if (string.IsNullOrEmpty(token.Lang))
            {
                return((StringBuffer)"<pre><code>" + (escaped ? code : StringHelper.Escape(code, true)) + "\n</code></pre>");
            }

            return("<pre><code class=\""
                   + engine.Options.LangPrefix
                   + StringHelper.Escape(token.Lang, true)
                   + "\">"
                   + (escaped ? code : StringHelper.Escape(code, true))
                   + "\n</code></pre>\n");
        }
Example #6
0
        protected StringBuffer RenderTokens(MarkdownEngine engine, ImmutableArray <IMarkdownToken> tokens, MarkdownBlockContext context, bool wrapParagraph = false, IMarkdownRule rule = null)
        {
            var content     = StringBuffer.Empty;
            var textContent = StringBuffer.Empty;

            foreach (var t in tokens)
            {
                var text = t as MarkdownTextToken;
                if (text != null)
                {
                    if (textContent != StringBuffer.Empty)
                    {
                        textContent += "\n";
                    }
                    textContent += text.Content;
                    continue;
                }
                if (!wrapParagraph && t is MarkdownNewLineBlockToken)
                {
                    continue;
                }
                if (textContent != StringBuffer.Empty)
                {
                    content    += RenderTextInTokens(engine, context, wrapParagraph, rule, textContent);
                    textContent = StringBuffer.Empty;
                }
                content += engine.Render(t, context);
            }
            if (textContent != StringBuffer.Empty)
            {
                content += RenderTextInTokens(engine, context, wrapParagraph, rule, textContent);
            }
            return(content);
        }
Example #7
0
        public virtual StringBuffer Render(MarkdownEngine engine, MarkdownBlockquoteBlockToken token, MarkdownBlockContext context)
        {
            StringBuffer content = "<blockquote>\n";

            content += RenderTokens(engine, token.Tokens, context, true, token.Rule);
            return(content + "</blockquote>\n");
        }
Example #8
0
        public virtual StringBuffer Render(MarkdownEngine engine, GfmDelInlineToken token, MarkdownInlineContext context)
        {
            var result = (StringBuffer)"<del>";

            result += engine.Mark(token.Content);
            result += "</del>";
            return(result);
        }
Example #9
0
        public virtual StringBuffer Render(MarkdownEngine engine, MarkdownTextToken token, MarkdownBlockContext context)
        {
            StringBuffer result = "<p>";

            result += token.Content;
            result += "</p>\n";
            return(result);
        }
Example #10
0
 public virtual IMarkdownToken TryMatch(MarkdownEngine engine, ref string source)
 {
     var match = Hr.Match(source);
     if (match.Length == 0)
     {
         return null;
     }
     source = source.Substring(match.Length);
     return new MarkdownHrBlockToken(this);
 }
Example #11
0
        public virtual StringBuffer Render(MarkdownEngine engine, MarkdownParagraphBlockToken token, MarkdownBlockContext context)
        {
            StringBuffer result = "<p>";
            var          c      = engine.SwitchContext(context.InlineContext);

            result += engine.Mark(token.Content);
            engine.SwitchContext(c);
            result += "</p>\n";
            return(result);
        }
 public virtual IMarkdownToken TryMatch(MarkdownEngine engine, ref string source)
 {
     var match = LHeading.Match(source);
     if (match.Length == 0)
     {
         return null;
     }
     source = source.Substring(match.Length);
     return new MarkdownHeadingBlockToken(this, match.Groups[1].Value, match.Groups[2].Value == "=" ? 1 : 2);
 }
 public virtual IMarkdownToken TryMatch(MarkdownEngine engine, ref string source)
 {
     var match = Newline.Match(source);
     if (match.Length == 0)
     {
         return null;
     }
     source = source.Substring(match.Length);
     return new MarkdownNewLineBlockToken(this, match.Value);
 }
 public virtual IMarkdownToken TryMatch(MarkdownEngine engine, ref string source)
 {
     var match = Escape.Match(source);
     if (match.Length == 0)
     {
         return null;
     }
     source = source.Substring(match.Length);
     return new MarkdownEscapeInlineToken(this, match.Groups[1].Value);
 }
 public virtual IMarkdownToken TryMatch(MarkdownEngine 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);
     return new MarkdownBlockquoteBlockToken(this, engine.Tokenize(capStr));
 }
Example #16
0
 private StringBuffer RenderTextInTokens(MarkdownEngine engine, MarkdownBlockContext context, bool wrapParagraph, IMarkdownRule rule, StringBuffer textContent)
 {
     if (wrapParagraph)
     {
         return(Render(engine, new MarkdownParagraphBlockToken(rule, textContent), context));
     }
     else
     {
         return(ApplyInline(engine, textContent, context));
     }
 }
Example #17
0
        public IMarkdownToken TryMatch(MarkdownEngine engine, ref string source)
        {
            var match = Fences.Match(source);
            if (match.Length == 0)
            {
                return null;
            }
            source = source.Substring(match.Length);

            return new MarkdownCodeBlockToken(this, match.Groups[3].Value, match.Groups[2].Value);
        }
Example #18
0
        public virtual IMarkdownToken TryMatch(MarkdownEngine engine, ref string source)
        {
            var match = Newline.Match(source);

            if (match.Length == 0)
            {
                return(null);
            }
            source = source.Substring(match.Length);
            return(new MarkdownNewLineBlockToken(this, match.Value));
        }
Example #19
0
        public virtual IMarkdownToken TryMatch(MarkdownEngine engine, ref string source)
        {
            var match = Em.Match(source);
            if (match.Length == 0)
            {
                return null;
            }
            source = source.Substring(match.Length);

            return new MarkdownEmInlineToken(this, match.NotEmpty(2, 1));
        }
Example #20
0
        public IMarkdownToken Rewrite(MarkdownEngine engine, IMarkdownToken token)
        {
            var tengine = engine as TEngine;
            var ttoken  = token as TToken;

            if (tengine != null && ttoken != null)
            {
                return(RewriteFunc(tengine, ttoken));
            }
            return(null);
        }
Example #21
0
        public virtual IMarkdownToken TryMatch(MarkdownEngine engine, ref string source)
        {
            var match = Text.Match(source);
            if (match.Length == 0)
            {
                return null;
            }
            source = source.Substring(match.Length);

            return new MarkdownTextToken(this, StringHelper.Escape(Smartypants(engine.Options, match.Groups[0].Value)));
        }
Example #22
0
        public virtual IMarkdownToken TryMatch(MarkdownEngine engine, ref string source)
        {
            var match = LHeading.Match(source);

            if (match.Length == 0)
            {
                return(null);
            }
            source = source.Substring(match.Length);
            return(new MarkdownHeadingBlockToken(this, match.Groups[1].Value, match.Groups[2].Value == "=" ? 1 : 2));
        }
        public virtual IMarkdownToken TryMatch(MarkdownEngine engine, ref string source)
        {
            var match = Escape.Match(source);

            if (match.Length == 0)
            {
                return(null);
            }
            source = source.Substring(match.Length);
            return(new MarkdownEscapeInlineToken(this, match.Groups[1].Value));
        }
Example #24
0
        public virtual IMarkdownToken TryMatch(MarkdownEngine engine, ref string source)
        {
            var match = Hr.Match(source);

            if (match.Length == 0)
            {
                return(null);
            }
            source = source.Substring(match.Length);
            return(new MarkdownHrBlockToken(this));
        }
Example #25
0
        public override IMarkdownToken TryMatch(MarkdownEngine engine, ref string source)
        {
            var match = Link.Match(source);
            if (match.Length == 0)
            {
                return null;
            }
            source = source.Substring(match.Length);

            return GenerateToken(match.Groups[2].Value, match.Groups[3].Value, match.Groups[1].Value, match.Value[0] == '!');
        }
Example #26
0
        public virtual StringBuffer Render(MarkdownEngine engine, MarkdownImageInlineToken token, MarkdownInlineContext context)
        {
            var result = (StringBuffer)"<img src=\"" + token.Href + "\" alt=\"" + token.Text + "\"";

            if (!string.IsNullOrEmpty(token.Title))
            {
                result = result + " title=\"" + token.Title + "\"";
            }

            result += engine.Options.XHtml ? "/>" : ">";
            return(result);
        }
        public virtual IMarkdownToken TryMatch(MarkdownEngine engine, ref string source)
        {
            var match = Text.Match(source);

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

            return(new MarkdownTextToken(this, StringHelper.Escape(Smartypants(engine.Options, match.Groups[0].Value))));
        }
Example #28
0
        public override IMarkdownToken TryMatch(MarkdownEngine engine, ref string source)
        {
            var match = Link.Match(source);

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

            return(GenerateToken(match.Groups[2].Value, match.Groups[3].Value, match.Groups[1].Value, match.Value[0] == '!'));
        }
Example #29
0
 public virtual StringBuffer Render(MarkdownEngine engine, MarkdownTagInlineToken token, MarkdownInlineContext context)
 {
     if (engine.Options.Sanitize)
     {
         if (engine.Options.Sanitizer != null)
         {
             return(engine.Options.Sanitizer(token.Content));
         }
         return(StringHelper.Escape(token.Content));
     }
     return(token.Content);
 }
Example #30
0
        protected virtual StringBuffer ApplyInline(MarkdownEngine engine, StringBuffer content, MarkdownBlockContext context)
        {
            if (content == StringBuffer.Empty)
            {
                return(StringBuffer.Empty);
            }
            var c      = engine.SwitchContext(context.InlineContext);
            var result = engine.Mark(content.ToString());

            engine.SwitchContext(c);
            return(result);
        }
Example #31
0
        public IMarkdownToken TryMatch(MarkdownEngine engine, ref string source)
        {
            var match = Fences.Match(source);

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

            return(new MarkdownCodeBlockToken(this, match.Groups[3].Value, match.Groups[2].Value));
        }
        public virtual IMarkdownToken TryMatch(MarkdownEngine engine, ref string source)
        {
            var match = Strong.Match(source);

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

            return(new MarkdownStrongInlineToken(this, match.NotEmpty(2, 1)));
        }
Example #33
0
 public virtual StringBuffer Render(MarkdownEngine engine, MarkdownListBlockToken token, MarkdownBlockContext context)
 {
     var type = token.Ordered ? "ol" : "ul";
     StringBuffer content = "<";
     content += type;
     content += ">\n";
     foreach (var t in token.Tokens)
     {
         content += engine.Render(t, context);
     }
     return content + "</" + type + ">\n";
 }
Example #34
0
        public virtual StringBuffer Render(MarkdownEngine engine, MarkdownTableBlockToken token, MarkdownBlockContext context)
        {
            StringBuffer result = "<table>\n<thead>\n";

            // header
            result += "<tr>\n";
            var cell = StringBuffer.Empty;
            var c    = engine.SwitchContext(context.InlineContext);

            for (int i = 0; i < token.Header.Length; i++)
            {
                if (i < token.Align.Length && token.Align[i] != Align.NotSpec)
                {
                    result += "<th style=\"text-align:";
                    result += token.Align[i].ToString().ToLower();
                    result += "\">";
                }
                else
                {
                    result += "<th>";
                }
                result += engine.Mark(token.Header[i]);
                result += "</th>\n";
            }
            result += "</tr>\n";
            result += "</thead>\n";
            result += "<tbody>\n";
            // body
            for (int i = 0; i < token.Cells.Length; i++)
            {
                var row = token.Cells[i];
                result += "<tr>\n";
                for (int j = 0; j < row.Length; j++)
                {
                    if (j < token.Align.Length && token.Align[j] != Align.NotSpec)
                    {
                        result += "<td style=\"text-align:";
                        result += token.Align[j].ToString().ToLower();
                        result += "\">";
                    }
                    else
                    {
                        result += "<td>";
                    }
                    result += engine.Mark(row[j]);
                    result += "</td>\n";
                }
                result += "</tr>\n";
            }
            engine.SwitchContext(c);
            return(result + "</tbody>\n" + "</table>\n");
        }
        public virtual IMarkdownToken TryMatch(MarkdownEngine 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);

            return(new MarkdownBlockquoteBlockToken(this, engine.Tokenize(capStr)));
        }
Example #36
0
        public virtual StringBuffer Render(MarkdownEngine engine, MarkdownListBlockToken token, MarkdownBlockContext context)
        {
            var          type    = token.Ordered ? "ol" : "ul";
            StringBuffer content = "<";

            content += type;
            content += ">\n";
            foreach (var t in token.Tokens)
            {
                content += engine.Render(t, context);
            }
            return(content + "</" + type + ">\n");
        }
Example #37
0
 public virtual StringBuffer Render(MarkdownEngine engine, MarkdownHtmlBlockToken token, MarkdownBlockContext context)
 {
     if (!token.Pre && !engine.Options.Pedantic)
     {
         var c      = engine.SwitchContext(context.InlineContext);
         var result = engine.Mark(token.Content);
         engine.SwitchContext(c);
         return(result);
     }
     else
     {
         return(token.Content);
     }
 }
Example #38
0
 public virtual IMarkdownToken TryMatch(MarkdownEngine engine, ref string source)
 {
     if ((bool)engine.Context.Variables[MarkdownBlockContext.IsTop])
     {
         return null;
     }
     var match = Text.Match(source);
     if (match.Length == 0)
     {
         return null;
     }
     source = source.Substring(match.Length);
     return new MarkdownTextToken(this, match.Value);
 }
 public IMarkdownToken Rewrite(MarkdownEngine engine, IMarkdownToken token)
 {
     if (Rewriters.Count > 0)
     {
         foreach (var rewriter in Rewriters)
         {
             var newToken = rewriter.Rewrite(engine, token);
             if (newToken != null)
             {
                 return newToken;
             }
         }
     }
     return null;
 }
 public IMarkdownToken Rewrite(MarkdownEngine engine, IMarkdownToken token)
 {
     if (Rewriters.Count > 0)
     {
         foreach (var rewriter in Rewriters)
         {
             var newToken = rewriter.Rewrite(engine, token);
             if (newToken != null)
             {
                 return(newToken);
             }
         }
     }
     return(null);
 }
        public virtual IMarkdownToken TryMatch(MarkdownEngine engine, ref string source)
        {
            if ((bool)engine.Context.Variables[MarkdownBlockContext.IsTop])
            {
                return(null);
            }
            var match = Text.Match(source);

            if (match.Length == 0)
            {
                return(null);
            }
            source = source.Substring(match.Length);
            return(new MarkdownTextToken(this, match.Value));
        }
Example #42
0
 public IMarkdownToken Rewrite(MarkdownEngine engine, IMarkdownToken token)
 {
     IMarkdownToken lastToken;
     IMarkdownToken newToken = token;
     for (int loopCount = 0; loopCount < MaxLoopCount; loopCount++)
     {
         lastToken = newToken;
         newToken = Inner.Rewrite(engine, lastToken);
         if (newToken == null)
         {
             return lastToken;
         }
     }
     throw new InvalidOperationException("Too many loops!");
 }
            public IMarkdownToken Validate(MarkdownEngine engine, MarkdownTagInlineToken token)
            {
                var m = OpeningTag.Match(token.Content);
                bool isOpeningTag = true;
                if (m.Length == 0)
                {
                    m = ClosingTag.Match(token.Content);
                    if (m.Length == 0)
                    {
                        return null;
                    }
                    isOpeningTag = false;
                }

                return ValidateCore(token, m, isOpeningTag);
            }
Example #44
0
        public IMarkdownToken Rewrite(MarkdownEngine engine, IMarkdownToken token)
        {
            IMarkdownToken lastToken;
            IMarkdownToken newToken = token;

            for (int loopCount = 0; loopCount < MaxLoopCount; loopCount++)
            {
                lastToken = newToken;
                newToken  = Inner.Rewrite(engine, lastToken);
                if (newToken == null)
                {
                    return(lastToken);
                }
            }
            throw new InvalidOperationException("Too many loops!");
        }
 public virtual IMarkdownToken TryMatch(MarkdownEngine 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, content);
 }
Example #46
0
 public virtual StringBuffer Render(MarkdownEngine engine, MarkdownHeadingBlockToken token, MarkdownBlockContext context)
 {
     string level = token.Depth.ToString();
     var result = (StringBuffer)"<h"
         + level
         + " id=\""
         + engine.Options.HeaderPrefix
         + Regex.Replace(token.Content.ToLower(), @"[^\w]+", "-")
         + "\">";
     var c = engine.SwitchContext(context.InlineContext);
     result += engine.Mark(token.Content);
     engine.SwitchContext(c);
     result += "</h";
     result += level;
     result += ">\n";
     return result;
 }
 public virtual IMarkdownToken TryMatch(MarkdownEngine 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, header, align, cells);
 }
Example #48
0
        public virtual StringBuffer Render(MarkdownEngine engine, MarkdownHeadingBlockToken token, MarkdownBlockContext context)
        {
            string level  = token.Depth.ToString();
            var    result = (StringBuffer)"<h"
                            + level
                            + " id=\""
                            + engine.Options.HeaderPrefix
                            + Regex.Replace(token.Content.ToLower(), @"[^\w]+", "-")
                            + "\">";
            var c = engine.SwitchContext(context.InlineContext);

            result += engine.Mark(token.Content);
            engine.SwitchContext(c);
            result += "</h";
            result += level;
            result += ">\n";
            return(result);
        }
Example #49
0
 public virtual IMarkdownToken TryMatch(MarkdownEngine engine, ref string source)
 {
     var match = Regexes.Block.Code.Match(source);
     if (match.Length == 0)
     {
         return null;
     }
     source = source.Substring(match.Length);
     var capStr = Regexes.Lexers.LeadingWhiteSpaces.Replace(match.Value, string.Empty);
     if (engine.Options.Pedantic)
     {
         return new MarkdownCodeBlockToken(this, capStr);
     }
     else
     {
         return new MarkdownCodeBlockToken(this, Regexes.Lexers.TailingEmptyLines.Replace(capStr, string.Empty));
     }
 }
Example #50
0
 public virtual IMarkdownToken TryMatch(MarkdownEngine engine, ref string source)
 {
     if (!(bool)engine.Context.Variables[MarkdownBlockContext.IsTop])
     {
         return null;
     }
     var match = Def.Match(source);
     if (match.Length == 0)
     {
         return null;
     }
     source = source.Substring(match.Length);
     engine.Links[match.Groups[1].Value.ToLower()] = new LinkObj
     {
         Href = match.Groups[2].Value,
         Title = match.Groups[3].Value
     };
     return new MarkdownIgnoreToken(this);
 }
        public virtual IMarkdownToken TryMatch(MarkdownEngine 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, header, align, cells));
        }
Example #52
0
        public virtual IMarkdownToken TryMatch(MarkdownEngine 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, match.Value);
            }
            else
            {
                return new MarkdownHtmlBlockToken(this, match.Value, isPre);
            }
        }
Example #53
0
        public virtual IMarkdownToken TryMatch(MarkdownEngine 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, text, null, text);
        }
        public override IMarkdownToken TryMatch(MarkdownEngine engine, ref string source)
        {
            var match = RefLink.Match(source);
            if (match.Length == 0)
            {
                return null;
            }
            source = source.Substring(match.Length);

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

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

            if (string.IsNullOrEmpty(link?.Href))
            {
                source = match.Groups[0].Value.Substring(1) + source;
                return new MarkdownTextToken(this, match.Groups[0].Value[0].ToString());
            }
            return GenerateToken(link.Href, link.Title, match.Groups[1].Value, match.Value[0] == '!');
        }
Example #55
0
        public virtual IMarkdownToken TryMatch(MarkdownEngine engine, ref string source)
        {
            var match = Tag.Match(source);
            if (match.Length == 0)
            {
                return null;
            }
            source = source.Substring(match.Length);

            var context = engine.Context;
            var inLink = (bool)context.Variables[MarkdownInlineContext.IsInLink];
            if (!inLink && Regexes.Lexers.StartHtmlLink.IsMatch(match.Value))
            {
                engine.SwitchContext(MarkdownInlineContext.IsInLink, true);
            }
            else if (inLink && Regexes.Lexers.EndHtmlLink.IsMatch(match.Value))
            {
                engine.SwitchContext(MarkdownInlineContext.IsInLink, false);
            }
            return new MarkdownTagInlineToken(this, match.Value);
        }
Example #56
0
 public virtual StringBuffer Render(MarkdownEngine engine, MarkdownIgnoreToken token, IMarkdownContext context)
 {
     return StringBuffer.Empty;
 }
Example #57
0
 public virtual StringBuffer Render(MarkdownEngine engine, MarkdownHrBlockToken token, MarkdownBlockContext context)
 {
     return engine.Options.XHtml ? "<hr/>\n" : "<hr>\n";
 }
Example #58
0
 public virtual StringBuffer Render(MarkdownEngine engine, MarkdownBlockquoteBlockToken token, MarkdownBlockContext context)
 {
     StringBuffer content = "<blockquote>\n";
     content += RenderTokens(engine, token.Tokens, context, true, token.Rule);
     return content + "</blockquote>\n";
 }
Example #59
0
 public virtual StringBuffer Render(MarkdownEngine engine, MarkdownListItemBlockToken token, MarkdownBlockContext context)
 {
     StringBuffer content = "<li>";
     content += RenderTokens(engine, token.Tokens, context, token.Loose, token.Rule);
     return content + "</li>\n";
 }
Example #60
0
 protected StringBuffer RenderTokens(MarkdownEngine engine, ImmutableArray<IMarkdownToken> tokens, MarkdownBlockContext context, bool wrapParagraph = false, IMarkdownRule rule = null)
 {
     var content = StringBuffer.Empty;
     var textContent = StringBuffer.Empty;
     foreach (var t in tokens)
     {
         var text = t as MarkdownTextToken;
         if (text != null)
         {
             if (textContent != StringBuffer.Empty)
             {
                 textContent += "\n";
             }
             textContent += text.Content;
             continue;
         }
         if (!wrapParagraph && t is MarkdownNewLineBlockToken)
         {
             continue;
         }
         if (textContent != StringBuffer.Empty)
         {
             content += RenderTextInTokens(engine, context, wrapParagraph, rule, textContent);
             textContent = StringBuffer.Empty;
         }
         content += engine.Render(t, context);
     }
     if (textContent != StringBuffer.Empty)
     {
         content += RenderTextInTokens(engine, context, wrapParagraph, rule, textContent);
     }
     return content;
 }