예제 #1
0
 public virtual StringBuffer Render(IMarkdownRenderer engine, DfmXrefInlineToken token, MarkdownInlineContext context)
 {
     var href = token.Href == null ? string.Empty : $" href=\"{StringHelper.HtmlEncode(token.Href)}\"";
     var name = token.Name == null ? null : StringHelper.HtmlEncode(token.Name);
     var title = token.Title == null ? null : $" title=\"{StringHelper.HtmlEncode(token.Title)}\"";
     return $"<xref{href}{title}>{name}</xref>";
 }
예제 #2
0
파일: DfmRenderer.cs 프로젝트: dotnet/docfx
 public virtual StringBuffer Render(IMarkdownRenderer renderer, DfmIncludeInlineToken token, MarkdownInlineContext context)
 {
     lock (_inlineInclusionHelper)
     {
         return _inlineInclusionHelper.Load(renderer, token.Src, token.Raw, token.SourceInfo, context, (DfmEngine)renderer.Engine);
     }
 }
예제 #3
0
 public virtual StringBuffer Render(IMarkdownRenderer renderer, DfmXrefInlineToken token, MarkdownInlineContext context)
 {
     var childContent = StringBuffer.Empty;
     foreach (var item in token.Content)
     {
         childContent += renderer.Render(item);
     }
     return Insert(token, $"{ExposeTokenNameInDfm(token)}>{Escape(token.Href)}", childContent);
 }
예제 #4
0
 public virtual StringBuffer Render(IMarkdownRenderer render, MarkdownStrongInlineToken token, MarkdownInlineContext context)
 {
     StringBuffer content = StringBuffer.Empty;
     content += "**";
     foreach (var t in token.Content)
     {
         content += render.Render(t);
     }
     content += "**";
     return content;
 }
예제 #5
0
 public virtual StringBuffer Render(IMarkdownRenderer render, MarkdownImageInlineToken token, MarkdownInlineContext context)
 {
     switch(token.LinkType)
     {
         case MarkdownLinkType.NormalLink:
             return RenderImageNormalLink(render, token, context);
         case MarkdownLinkType.NumberLink:
             return RenderNumberLink(render, token, context);
         case MarkdownLinkType.RefLink:
             return RenderRefLink(render, token, context);
         default:
             throw new NotSupportedException($"Link type: {token.LinkType} doesn't support in Image Link Render");
     }
 }
예제 #6
0
 private StringBuffer RenderImageNormalLink(IMarkdownRenderer render, MarkdownImageInlineToken token, MarkdownInlineContext context)
 {
     StringBuffer content = StringBuffer.Empty;
     content += "![";
     content += token.Text;
     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;
 }
예제 #7
0
        public virtual StringBuffer Render(IMarkdownRenderer renderer, DfmXrefInlineToken token, MarkdownInlineContext context)
        {
            StringBuffer result = "<xref";
            result = AppendAttribute(result, "href", token.Href);
            result = AppendAttribute(result, "title", token.Title);
            result = AppendAttribute(result, "data-throw-if-not-resolved", token.ThrowIfNotResolved.ToString());
            result = AppendAttribute(result, "data-raw", token.RawMarkdown);
            
            result += ">";
            if (token.Name != null)
            {
                result += StringHelper.HtmlEncode(token.Name);
            }

            result += "</xref>";
            return result;
        }
예제 #8
0
파일: DfmRenderer.cs 프로젝트: dotnet/docfx
        public virtual StringBuffer Render(IMarkdownRenderer renderer, DfmXrefInlineToken token, MarkdownInlineContext context)
        {
            StringBuffer result = "<xref";
            result = AppendAttribute(result, "href", token.Href);
            result = AppendAttribute(result, "title", token.Title);
            result = AppendAttribute(result, "data-throw-if-not-resolved", token.ThrowIfNotResolved.ToString());
            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 += "</xref>";
            return result;
        }
예제 #9
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;
 }
예제 #10
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;
 }
예제 #11
0
 public virtual StringBuffer Render(IMarkdownRenderer renderer, DfmXrefInlineToken token, MarkdownInlineContext context)
 {
     StringBuffer result = "<xref";
     if (token.Href != null)
     {
         result += " href=\"";
         result += StringHelper.HtmlEncode(token.Href);
         result += "\"";
     }
     if (token.Title != null)
     {
         result += " title=\"";
         result += StringHelper.HtmlEncode(token.Title);
         result += "\"";
     }
     result += ">";
     if (token.Name != null)
     {
         result += StringHelper.HtmlEncode(token.Name);
     }
     result += "</xref>";
     return result;
 }
예제 #12
0
 public virtual StringBuffer Render(IMarkdownRenderer renderer, MarkdownTextToken token, MarkdownInlineContext context)
 {
     //return Insert(token, $"{ExposeTokenName(token)}>{Escape(token.Content)}");
     return(Insert(token, $"{Escape(token.Content)}"));
 }
예제 #13
0
 public virtual StringBuffer Render(MarkdownEngine engine, GfmDelInlineToken token, MarkdownInlineContext context)
 {
     var result = (StringBuffer)"<del>";
     result += engine.Mark(token.Content);
     result += "</del>";
     return result;
 }
예제 #14
0
 public virtual StringBuffer Render(IMarkdownRenderer engine, MarkdownEscapeInlineToken token, MarkdownInlineContext context)
 {
     return(token.Content);
 }
예제 #15
0
        public virtual StringBuffer Render(IMarkdownRenderer engine, GfmDelInlineToken token, MarkdownInlineContext context)
        {
            var result = (StringBuffer)"<del>";

            foreach (var item in token.Content)
            {
                result += engine.Render(item);
            }
            result += "</del>";
            return(result);
        }
예제 #16
0
        private StringBuffer RenderImageNormalLink(IMarkdownRenderer render, MarkdownImageInlineToken token, MarkdownInlineContext context)
        {
            StringBuffer content = StringBuffer.Empty;

            content += "![";
            content += token.Text;
            content += "](";
            content += StringHelper.EscapeMarkdown(token.Href);
            if (!string.IsNullOrEmpty(token.Title))
            {
                content += " \"";
                content += StringHelper.EscapeMarkdown(token.Title);
                content += "\"";
            }
            content += ")";
            return(content);
        }
예제 #17
0
 public virtual StringBuffer Render(MarkdownEngine engine, MarkdownTextToken token, MarkdownInlineContext context)
 {
     return(token.Content);
 }
예제 #18
0
 private StringBuffer RenderUrlLink(IMarkdownRenderer render, MarkdownLinkInlineToken token, MarkdownInlineContext context)
 {
     return token.Href;
 }
예제 #19
0
        private StringBuffer RenderAutoLink(IMarkdownRenderer render, MarkdownLinkInlineToken token, MarkdownInlineContext context)
        {
            StringBuffer content = StringBuffer.Empty;

            content += "<";
            content += StringHelper.EscapeMarkdownHref(token.Href);
            content += ">";
            return(content);
        }
예제 #20
0
 private StringBuffer RenderUrlLink(IMarkdownRenderer render, MarkdownLinkInlineToken token, MarkdownInlineContext context)
 {
     return(StringHelper.EscapeMarkdownHref(token.Href));
 }
예제 #21
0
        private StringBuffer RenderNumberLink(IMarkdownRenderer render, IMarkdownToken token, MarkdownInlineContext context)
        {
            StringBuffer content = StringBuffer.Empty;

            if (token is MarkdownImageInlineToken)
            {
                var realToken = token as MarkdownImageInlineToken;
                content += "![";
                content += realToken.Text;
                content += "]";
            }
            else if (token is MarkdownLinkInlineToken)
            {
                var realToken = token as MarkdownLinkInlineToken;
                content += "[";
                foreach (var t in realToken.Content)
                {
                    content += render.Render(t);
                }
                content += "]";
            }
            else
            {
                throw new NotSupportedException("Number link token should be either link token or image token");
            }

            return(content);
        }
예제 #22
0
        private StringBuffer RenderRefLink(IMarkdownRenderer render, IMarkdownToken token, MarkdownInlineContext context)
        {
            StringBuffer content = StringBuffer.Empty;

            if (token is MarkdownImageInlineToken)
            {
                var realToken = token as MarkdownImageInlineToken;
                content += "![";
                if (render.Options.LegacyMode)
                {
                    content += StringHelper.LegacyEscapeMarkdown(realToken.Text);
                }
                else
                {
                    content += StringHelper.EscapeMarkdown(realToken.Text);
                }
                content += "][";
                content += realToken.RefId;
                content += "]";
            }
            else if (token is MarkdownLinkInlineToken)
            {
                var realToken = token as MarkdownLinkInlineToken;
                content += "[";
                foreach (var t in realToken.Content)
                {
                    content += render.Render(t);
                }
                content += "][";
                content += realToken.RefId;
                content += "]";
            }
            else
            {
                throw new NotSupportedException("Reference link token should be either link token or image token");
            }

            return(content);
        }
예제 #23
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);
        }
예제 #24
0
 public virtual StringBuffer Render(IMarkdownRenderer renderer, MarkdownBrInlineToken token, MarkdownInlineContext context)
 {
     return(Insert(token, ExposeTokenName(token)));
 }
예제 #25
0
        public virtual StringBuffer Render(IMarkdownRenderer render, MarkdownImageInlineToken token, MarkdownInlineContext context)
        {
            StringBuffer content = StringBuffer.Empty;

            content += "![";
            content += token.Text;
            content += "](";
            content += Regexes.Helper.MarkdownUnescape.Replace(StringHelper.Unescape(token.Href), m => "\\" + m.Value);
            if (!string.IsNullOrEmpty(token.Title))
            {
                content += " \"";
                content += Regexes.Helper.MarkdownUnescape.Replace(StringHelper.Unescape(token.Title), m => "\\" + m.Value);
                content += "\"";
            }
            content += ")";
            return(content);
        }
예제 #26
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);
 }
예제 #27
0
        public virtual StringBuffer Render(IMarkdownRenderer render, MarkdownStrongInlineToken token, MarkdownInlineContext context)
        {
            StringBuffer content = StringBuffer.Empty;

            content += "**";
            foreach (var t in token.Content)
            {
                content += render.Render(t);
            }
            content += "**";
            return(content);
        }
예제 #28
0
 public virtual StringBuffer Render(MarkdownEngine engine, MarkdownBrInlineToken token, MarkdownInlineContext context)
 {
     return(engine.Options.XHtml ? "<br/>" : "<br>");
 }
예제 #29
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;
        }
예제 #30
0
 private StringBuffer RenderAutoLink(IMarkdownRenderer render, MarkdownLinkInlineToken token, MarkdownInlineContext context)
 {
     StringBuffer content = StringBuffer.Empty;
     content += "<";
     content += token.Href;
     content += ">";
     return content;
 }
예제 #31
0
        private StringBuffer RenderNumberLink(IMarkdownRenderer render, IMarkdownToken token, MarkdownInlineContext context)
        {
            StringBuffer content = StringBuffer.Empty;
            if(token is MarkdownImageInlineToken)
            {
                var realToken = token as MarkdownImageInlineToken;
                content += "![";
                content += realToken.Text;
                content += "]";
            }
            else if(token is MarkdownLinkInlineToken)
            {
                var realToken = token as MarkdownLinkInlineToken;
                content += "[";
                foreach (var t in realToken.Content)
                {
                    content += render.Render(t);
                }
                content += "]";
            }
            else
            {
                throw new NotSupportedException("Number link token should be either link token or image token");
            }

            return content;
        }
예제 #32
0
 public virtual StringBuffer Render(IMarkdownRenderer renderer, MarkdownImageInlineToken token, MarkdownInlineContext context)
 {
     return(Insert(token, $"{ExposeTokenName(token)}>{Escape(token.Href)}"));
 }
예제 #33
0
 public virtual StringBuffer Render(MarkdownEngine engine, MarkdownEscapeInlineToken token, MarkdownInlineContext context)
 {
     return token.Content;
 }
예제 #34
0
 public virtual StringBuffer Render(IMarkdownRenderer engine, MarkdownCodeInlineToken token, MarkdownInlineContext context)
 {
     return (StringBuffer)"<code>" + StringHelper.Escape(token.Content, true) + "</code>";
 }
예제 #35
0
 private StringBuffer RenderUrlLink(IMarkdownRenderer render, MarkdownLinkInlineToken token, MarkdownInlineContext context)
 {
     return(token.Href);
 }
예제 #36
0
 public virtual StringBuffer Render(IMarkdownRenderer render, AzureIncludeInlineToken token, MarkdownInlineContext context)
 {
     return RenderAzureIncludeToken(render, token, context);
 }
예제 #37
0
 public virtual StringBuffer Render(IMarkdownRenderer engine, MarkdownTagInlineToken token, MarkdownInlineContext context)
 {
     if (engine.Options.Sanitize)
     {
         if (engine.Options.Sanitizer != null)
         {
             return engine.Options.Sanitizer(token.RawMarkdown);
         }
         return StringHelper.Escape(token.RawMarkdown);
     }
     return token.RawMarkdown;
 }
예제 #38
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;
        }
예제 #39
0
 public virtual StringBuffer Render(IMarkdownRenderer engine, MarkdownTextToken token, MarkdownInlineContext context)
 {
     return token.Content;
 }
예제 #40
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);
        }
예제 #41
0
        public virtual StringBuffer Render(IMarkdownRenderer renderer, GfmDelInlineToken token, MarkdownInlineContext context)
        {
            var childContent = StringBuffer.Empty;

            foreach (var item in token.Content)
            {
                childContent += renderer.Render(item);
            }
            return(Insert(token, ExposeTokenName(token), childContent));
        }
예제 #42
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");
            }
        }
예제 #43
0
 public virtual StringBuffer Render(IMarkdownRenderer renderer, DfmIncludeInlineToken token, MarkdownInlineContext context)
 {
     return Insert(token, ExposeTokenNameInDfm(token));
 }
예제 #44
0
        public virtual StringBuffer Render(IMarkdownRenderer 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;
        }
예제 #45
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);
        }
예제 #46
0
 public virtual StringBuffer Render(IMarkdownRenderer engine, GfmDelInlineToken token, MarkdownInlineContext context)
 {
     var result = (StringBuffer)"<del>";
     foreach (var item in token.Content)
     {
         result += engine.Render(item);
     }
     result += "</del>";
     return result;
 }
예제 #47
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);
        }
예제 #48
0
 public virtual StringBuffer Render(IMarkdownRenderer engine, MarkdownBrInlineToken token, MarkdownInlineContext context)
 {
     return engine.Options.XHtml ? "<br/>" : "<br>";
 }
예제 #49
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);
        }
예제 #50
0
 public virtual StringBuffer Render(IMarkdownRenderer render, DfmIncludeInlineToken token, MarkdownInlineContext context)
 {
     return string.IsNullOrEmpty(token.Title)
             ? $"[!INCLUDE [{token.Name}]({token.Src})]"
             : $"[!INCLUDE [{token.Name}]({token.Src} \"{token.Title}\")]";
 }
예제 #51
0
 public virtual StringBuffer Render(MarkdownEngine engine, MarkdownCodeInlineToken token, MarkdownInlineContext context)
 {
     return((StringBuffer)"<code>" + StringHelper.Escape(token.Content, true) + "</code>");
 }
예제 #52
0
 public virtual StringBuffer Render(IMarkdownRenderer renderer, DfmIncludeInlineToken token, MarkdownInlineContext context)
 {
     var resolved = _inlineInclusionHelper.Load(renderer, token.Src, token.Raw, context, ((DfmEngine)renderer.Engine).InternalMarkup);
     return resolved;
 }
예제 #53
0
        public virtual StringBuffer Render(MarkdownEngine engine, GfmDelInlineToken token, MarkdownInlineContext context)
        {
            var result = (StringBuffer)"<del>";

            result += engine.Mark(token.Content);
            result += "</del>";
            return(result);
        }