示例#1
0
        private StringBuffer RenderLinkNormalLink(IMarkdownRenderer render, MarkdownLinkInlineToken token, MarkdownInlineContext context)
        {
            StringBuffer content = StringBuffer.Empty;

            content += "[";
            foreach (var t in token.Content)
            {
                content += render.Render(t);
            }
            content += "](";
            content += StringHelper.EscapeMarkdownHref(token.Href);
            if (!string.IsNullOrEmpty(token.Title))
            {
                content += " \"";
                if (render.Options.LegacyMode)
                {
                    content += StringHelper.LegacyEscapeMarkdown(token.Title);
                }
                else
                {
                    content += StringHelper.EscapeMarkdown(token.Title);
                }
                content += "\"";
            }
            content += ")";
            return(content);
        }
示例#2
0
        private StringBuffer RenderAutoLink(IMarkdownRenderer render, MarkdownLinkInlineToken token, MarkdownInlineContext context)
        {
            StringBuffer content = StringBuffer.Empty;

            content += "<";
            content += token.Href;
            content += ">";
            return(content);
        }
示例#3
0
        public virtual StringBuffer Render(IMarkdownRenderer renderer, MarkdownLinkInlineToken token, MarkdownInlineContext context)
        {
            var childContent = StringBuffer.Empty;

            foreach (var item in token.Content)
            {
                childContent += renderer.Render(item);
            }
            return(Insert(token, ExposeTokenName(token), childContent));
        }
        public virtual StringBuffer Render(IMarkdownRenderer renderer, MarkdownLinkInlineToken token, MarkdownInlineContext context)
        {
            var childContent = StringBuffer.Empty;

            foreach (var item in token.Content)
            {
                childContent += renderer.Render(item);
            }
            return(this.Insert("Link", childContent, Type.NonLeaf));
        }
示例#5
0
 public virtual StringBuffer Render(IMarkdownRenderer render, MarkdownLinkInlineToken token, MarkdownInlineContext context)
 {
     switch (token.LinkType)
     {
         case MarkdownLinkType.AutoLink:
             return RenderAutoLink(render, token, context);
         case MarkdownLinkType.NormalLink:
             return RenderLinkNormalLink(render, token, context);
         case MarkdownLinkType.NumberLink:
             return RenderNumberLink(render, token, context);
         case MarkdownLinkType.RefLink:
             return RenderRefLink(render, token, context);
         case MarkdownLinkType.UrlLink:
             return RenderUrlLink(render, token, context);
         default:
             throw new NotSupportedException($"Link type: {token.LinkType} doesn't support in Link Render");
     }
 }
示例#6
0
        public virtual StringBuffer Render(MarkdownEngine engine, MarkdownLinkInlineToken token, MarkdownInlineContext context)
        {
            if (engine.Options.Sanitize)
            {
                string prot = null;

                try
                {
                    prot = Regex.Replace(StringHelper.DecodeURIComponent(StringHelper.Unescape(token.Href)), @"[^\w:]", string.Empty).ToLower();
                }
                catch (Exception)
                {
                    return(string.Empty);
                }

                if (prot.IndexOf("javascript:") == 0 || prot.IndexOf("vbscript:") == 0)
                {
                    return(string.Empty);
                }
            }

            var result = (StringBuffer)"<a href=\"" + token.Href + "\"";

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

            result += ">";
            if (token.ShouldApplyInlineRule)
            {
                engine.SwitchContext(MarkdownInlineContext.IsInLink, true);
                result += engine.Mark(token.Text);
                engine.SwitchContext(MarkdownInlineContext.IsInLink, false);
            }
            else
            {
                result += token.Text;
            }

            result += "</a>";
            return(result);
        }
示例#7
0
 private StringBuffer RenderLinkNormalLink(IMarkdownRenderer render, MarkdownLinkInlineToken token, MarkdownInlineContext context)
 {
     StringBuffer content = StringBuffer.Empty;
     content += "[";
     foreach (var t in token.Content)
     {
         content += render.Render(t);
     }
     content += "](";
     content += Regexes.Helper.MarkdownUnescape.Replace(token.Href, m => "\\" + m.Value);
     if (!string.IsNullOrEmpty(token.Title))
     {
         content += " \"";
         content += Regexes.Helper.MarkdownUnescape.Replace(token.Title, m => "\\" + m.Value);
         content += "\"";
     }
     content += ")";
     return content;
 }
示例#8
0
 public virtual StringBuffer Render(IMarkdownRenderer render, MarkdownLinkInlineToken token, MarkdownInlineContext context)
 {
     StringBuffer content = StringBuffer.Empty;
     content += "[";
     foreach(var t in token.Content)
     {
         content += render.Render(t);
     }
     content += "](";
     content += StringHelper.Unescape(token.Href);
     if (!string.IsNullOrEmpty(token.Title))
     {
         content += " \"";
         content += StringHelper.Unescape(token.Title);
         content += "\"";
     }
     content += ")";
     return content;
 }
示例#9
0
        private StringBuffer RenderLinkNormalLink(IMarkdownRenderer render, MarkdownLinkInlineToken token, MarkdownInlineContext context)
        {
            StringBuffer content = StringBuffer.Empty;

            content += "[";
            foreach (var t in token.Content)
            {
                content += render.Render(t);
            }
            content += "](";
            content += Regexes.Helper.MarkdownUnescape.Replace(token.Href, m => "\\" + m.Value);
            if (!string.IsNullOrEmpty(token.Title))
            {
                content += " \"";
                content += Regexes.Helper.MarkdownUnescape.Replace(token.Title, m => "\\" + m.Value);
                content += "\"";
            }
            content += ")";
            return(content);
        }
示例#10
0
        public virtual StringBuffer Render(IMarkdownRenderer render, MarkdownLinkInlineToken token, MarkdownInlineContext context)
        {
            StringBuffer content = StringBuffer.Empty;

            content += "[";
            foreach (var t in token.Content)
            {
                content += render.Render(t);
            }
            content += "](";
            content += StringHelper.Unescape(token.Href);
            if (!string.IsNullOrEmpty(token.Title))
            {
                content += " \"";
                content += StringHelper.Unescape(token.Title);
                content += "\"";
            }
            content += ")";
            return(content);
        }
示例#11
0
        public virtual StringBuffer Render(IMarkdownRenderer renderer, MarkdownLinkInlineToken token, MarkdownInlineContext context)
        {
            if (renderer.Options.Sanitize)
            {
                string prot = null;

                try
                {
                    prot = Regex.Replace(StringHelper.DecodeURIComponent(token.Href), @"[^\w:]", string.Empty).ToLower();
                }
                catch (Exception)
                {
                    return(string.Empty);
                }

                if (prot.IndexOf("javascript:") == 0 || prot.IndexOf("vbscript:") == 0)
                {
                    return(string.Empty);
                }
            }

            var result = (StringBuffer)"<a href=\"" + StringHelper.Escape(token.Href) + "\"";

            if (!string.IsNullOrEmpty(token.Title))
            {
                result = result + " title=\"" + StringHelper.Escape(token.Title) + "\"";
            }
            result  = AppendAttribute(result, "data-raw-source", token.SourceInfo.Markdown);
            result  = AppendSourceInfo(result, renderer, token);
            result += ">";

            foreach (var item in token.Content)
            {
                result += renderer.Render(item);
            }

            result += "</a>";
            return(result);
        }
示例#12
0
        public virtual StringBuffer Render(IMarkdownRenderer render, MarkdownLinkInlineToken token, MarkdownInlineContext context)
        {
            switch (token.LinkType)
            {
            case MarkdownLinkType.AutoLink:
                return(RenderAutoLink(render, token, context));

            case MarkdownLinkType.NormalLink:
                return(RenderLinkNormalLink(render, token, context));

            case MarkdownLinkType.NumberLink:
                return(RenderNumberLink(render, token, context));

            case MarkdownLinkType.RefLink:
                return(RenderRefLink(render, token, context));

            case MarkdownLinkType.UrlLink:
                return(RenderUrlLink(render, token, context));

            default:
                throw new NotSupportedException($"Link type: {token.LinkType} doesn't support in Link Render");
            }
        }
示例#13
0
        public virtual StringBuffer Render(IMarkdownRenderer engine, MarkdownLinkInlineToken token, MarkdownInlineContext context)
        {
            if (engine.Options.Sanitize)
            {
                string prot = null;

                try
                {
                    prot = Regex.Replace(StringHelper.DecodeURIComponent(StringHelper.Unescape(token.Href)), @"[^\w:]", string.Empty).ToLower();
                }
                catch (Exception)
                {
                    return(string.Empty);
                }

                if (prot.IndexOf("javascript:") == 0 || prot.IndexOf("vbscript:") == 0)
                {
                    return(string.Empty);
                }
            }

            var result = (StringBuffer)"<a href=\"" + token.Href + "\"";

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

            foreach (var item in token.Content)
            {
                result += engine.Render(item);
            }

            result += "</a>";
            return(result);
        }
示例#14
0
        public virtual StringBuffer Render(MarkdownEngine engine, MarkdownLinkInlineToken token, MarkdownInlineContext context)
        {
            if (engine.Options.Sanitize)
            {
                string prot = null;

                try
                {
                    prot = Regex.Replace(StringHelper.DecodeURIComponent(StringHelper.Unescape(token.Href)), @"[^\w:]", string.Empty).ToLower();
                }
                catch (Exception)
                {
                    return string.Empty;
                }

                if (prot.IndexOf("javascript:") == 0 || prot.IndexOf("vbscript:") == 0)
                {
                    return string.Empty;
                }
            }

            var result = (StringBuffer)"<a href=\"" + token.Href + "\"";
            if (!string.IsNullOrEmpty(token.Title))
            {
                result = result + " title=\"" + token.Title + "\"";
            }

            result += ">";
            if (token.ShouldApplyInlineRule)
            {
                engine.SwitchContext(MarkdownInlineContext.IsInLink, true);
                result += engine.Mark(token.Text);
                engine.SwitchContext(MarkdownInlineContext.IsInLink, false);
            }
            else
            {
                result += token.Text;
            }

            result += "</a>";
            return result;
        }
示例#15
0
 private StringBuffer RenderAutoLink(IMarkdownRenderer render, MarkdownLinkInlineToken token, MarkdownInlineContext context)
 {
     StringBuffer content = StringBuffer.Empty;
     content += "<";
     content += token.Href;
     content += ">";
     return content;
 }
示例#16
0
        public virtual StringBuffer Render(IMarkdownRenderer engine, MarkdownLinkInlineToken token, MarkdownInlineContext context)
        {
            if (engine.Options.Sanitize)
            {
                string prot = null;

                try
                {
                    prot = Regex.Replace(StringHelper.DecodeURIComponent(StringHelper.Unescape(token.Href)), @"[^\w:]", string.Empty).ToLower();
                }
                catch (Exception)
                {
                    return string.Empty;
                }

                if (prot.IndexOf("javascript:") == 0 || prot.IndexOf("vbscript:") == 0)
                {
                    return string.Empty;
                }
            }

            var result = (StringBuffer)"<a href=\"" + token.Href + "\"";
            if (!string.IsNullOrEmpty(token.Title))
            {
                result = result + " title=\"" + token.Title + "\"";
            }
            result += ">";

            foreach (var item in token.Content)
            {
                result += engine.Render(item);
            }

            result += "</a>";
            return result;
        }
示例#17
0
 private StringBuffer RenderUrlLink(IMarkdownRenderer render, MarkdownLinkInlineToken token, MarkdownInlineContext context)
 {
     return token.Href;
 }
示例#18
0
 private StringBuffer RenderUrlLink(IMarkdownRenderer render, MarkdownLinkInlineToken token, MarkdownInlineContext context)
 {
     return(StringHelper.EscapeMarkdownHref(token.Href));
 }
示例#19
0
 private StringBuffer RenderUrlLink(IMarkdownRenderer render, MarkdownLinkInlineToken token, MarkdownInlineContext context)
 {
     return(token.Href);
 }