Beispiel #1
0
        /// <summary>
        /// Displays a link tag.
        /// </summary>
        /// <param name="link"></param>
        /// <param name="innerText"></param>
        /// <param name="cssClass"></param>
        /// <returns></returns>
        public static HtmlString GetLink(this Link link, string innerText = null, string cssClass = null)
        {
            if (!link.IsValidLink())
            {
                return(null);
            }

            var tagBuilder = new TagBuilder("a");

            tagBuilder.MergeAttribute("href", link?.Url);

            if (!string.IsNullOrEmpty(link?.Target))
            {
                tagBuilder.MergeAttribute("target", link?.Target);
            }

            if (cssClass != null)
            {
                tagBuilder.MergeAttribute("class", cssClass);
            }
            tagBuilder.SetInnerText(innerText ?? link?.Name);

            OnLinkBuilderCustomisation?.Invoke(tagBuilder, link: link);

            return(new HtmlString(tagBuilder.ToString()));
        }
Beispiel #2
0
        /// <summary>
        /// Surrounds this HtmlString with a link tag.
        /// </summary>
        /// <param name="str"></param>
        /// <param name="url"></param>
        /// <param name="target"></param>
        /// <returns></returns>
        public static HtmlString SurroundWithLink(this IHtmlString str, string url, string target = null)
        {
            if (str == null)
            {
                return(null);
            }
            var tagBuilder = new TagBuilder("a");

            tagBuilder.MergeAttribute("href", url);

            if (!string.IsNullOrEmpty(target))
            {
                tagBuilder.MergeAttribute("target", target);
            }

            tagBuilder.InnerHtml = str.ToString();

            OnLinkBuilderCustomisation?.Invoke(tagBuilder, url: url, target: target);

            return(new HtmlString(tagBuilder.ToString()));
        }
Beispiel #3
0
        /// <summary>
        /// Works for SingleUrlPicker. Adds a link around some content. Will show only the content if link is not set.
        /// </summary>
        /// <param name="link"></param>
        /// <param name="content"></param>
        /// <param name="cssClass"></param>
        public static IHtmlString SurroundWithLink(this IHtmlString content, Link link, string cssClass = null)
        {
            if (link == null || content == null)
            {
                return(content);
            }
            var tagBuilder = new TagBuilder("a");

            tagBuilder.MergeAttribute("href", link.Url);

            if (!string.IsNullOrEmpty(link.Target))
            {
                tagBuilder.MergeAttribute("target", link.Target);
            }

            tagBuilder.MergeAttribute("class", cssClass);
            tagBuilder.InnerHtml = content.ToString();

            OnLinkBuilderCustomisation?.Invoke(tagBuilder, link: link);

            return(new HtmlString(tagBuilder.ToString()));
        }
Beispiel #4
0
        /// <summary>
        /// Surrounds this HtmlString with a link tag.
        /// If link is not defined then only the HtmlString will display.
        /// </summary>
        /// <param name="str"></param>
        /// <param name="link"></param>
        /// <returns></returns>
        public static HtmlString SurroundWithLink(this HtmlString str, Link link)
        {
            if (link == null || str == null)
            {
                return(str);
            }

            var tagBuilder = new TagBuilder("a");

            tagBuilder.MergeAttribute("href", link?.Url);

            if (!string.IsNullOrEmpty(link?.Target))
            {
                tagBuilder.MergeAttribute("target", link?.Target);
            }

            tagBuilder.InnerHtml = str.ToString();

            OnLinkBuilderCustomisation?.Invoke(tagBuilder, link: link);

            return(new HtmlString(tagBuilder.ToString()));
        }