コード例 #1
0
        public virtual StringBuffer Render(IMarkdownRenderer render, MarkdownImageInlineToken token, MarkdownInlineContext context)
        {
            StringBuffer content = StringBuffer.Empty;

            content += "![";
            content += token.Text;
            content += "](";
            content += StringHelper.Unescape(token.Href);
            if (!string.IsNullOrEmpty(token.Title))
            {
                content += " \"";
                content += StringHelper.Unescape(token.Title);
                content += "\"";
            }
            content += ")";
            return(content);
        }
コード例 #2
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);
        }
コード例 #3
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);
        }
コード例 #4
0
ファイル: HtmlRenderer.cs プロジェクト: stuartleeks/docfx
        public virtual StringBuffer Render(IMarkdownRenderer renderer, MarkdownLinkInlineToken token, MarkdownInlineContext context)
        {
            if (renderer.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 += renderer.Render(item);
            }

            result += "</a>";
            return(result);
        }