Search Results for

    Show / Hide Table of Contents
    View Source

    Class HtmlImageSourceParser

    Utility class used to parse and update image sources in HTML content based on Umbraco media references.

    Inheritance
    object
    Namespace: Umbraco.Cms.Core.Templates
    Assembly: Umbraco.Core.dll
    Syntax
    public sealed class HtmlImageSourceParser

    Constructors

    View Source

    HtmlImageSourceParser(Func<Guid, string>)

    Initializes a new instance of the HtmlImageSourceParser class.

    Declaration
    [Obsolete("Please use the constructor that accepts IImageUrlTokenGenerator. Scheduled for removal in Umbraco 19.")]
    public HtmlImageSourceParser(Func<Guid, string> getMediaUrl)
    Parameters
    Type Name Description
    Func<Guid, string> getMediaUrl

    A function that retrieves the media URL for a given GUID.

    View Source

    HtmlImageSourceParser(Func<Guid, string>, IImageUrlTokenGenerator)

    Initializes a new instance of the HtmlImageSourceParser class.

    Declaration
    public HtmlImageSourceParser(Func<Guid, string> getMediaUrl, IImageUrlTokenGenerator imageUrlTokenGenerator)
    Parameters
    Type Name Description
    Func<Guid, string> getMediaUrl

    A function that retrieves the media URL for a given GUID.

    IImageUrlTokenGenerator imageUrlTokenGenerator

    Used to re-sign rendered image URLs against the current HMAC secret key.

    View Source

    HtmlImageSourceParser(IPublishedUrlProvider)

    Initializes a new instance of the HtmlImageSourceParser class.

    Declaration
    [Obsolete("Please use the constructor that accepts IImageUrlTokenGenerator. Scheduled for removal in Umbraco 19.")]
    public HtmlImageSourceParser(IPublishedUrlProvider publishedUrlProvider)
    Parameters
    Type Name Description
    IPublishedUrlProvider publishedUrlProvider

    The published URL provider for resolving media URLs.

    View Source

    HtmlImageSourceParser(IPublishedUrlProvider, IImageUrlTokenGenerator)

    Initializes a new instance of the HtmlImageSourceParser class.

    Declaration
    public HtmlImageSourceParser(IPublishedUrlProvider publishedUrlProvider, IImageUrlTokenGenerator imageUrlTokenGenerator)
    Parameters
    Type Name Description
    IPublishedUrlProvider publishedUrlProvider

    The published URL provider for resolving media URLs.

    IImageUrlTokenGenerator imageUrlTokenGenerator

    Used to re-sign rendered image URLs against the current HMAC secret key.

    Methods

    View Source

    EnsureImageSources(string)

    Refreshes the src attribute of every Umbraco <img> tag in the supplied HTML so the rendered URL points at the current media path and carries an up-to-date HMAC signature.

    Declaration
    public string EnsureImageSources(string text)
    Parameters
    Type Name Description
    string text

    The HTML text to process.

    Returns
    Type Description
    string

    The HTML with each <img data-udi="..."> rewritten: the path is replaced with the current media URL (preserving the persisted query string), and any HMAC token in the query is re-signed against the currently configured secret key. Other tags are returned unchanged.

    Remarks

    Umbraco image tags are identified by their data-udi attributes.

    View Source

    FindUdisFromDataAttributes(string)

    Parses media UDIs out of an HTML string by reading data-udi attributes on <a> and <img> tags.

    Declaration
    public IEnumerable<Udi> FindUdisFromDataAttributes(string text)
    Parameters
    Type Name Description
    string text

    The HTML text to scan.

    Returns
    Type Description
    IEnumerable<Udi>

    The parseable UDIs found on data-udi attributes, in document order.

    View Source

    RemoveImageSources(string)

    Clears the media path from the src attribute of every <img> tag that has a data-udi attribute, preserving any query string the URL carried.

    Declaration
    public string RemoveImageSources(string text)
    Parameters
    Type Name Description
    string text

    The HTML text to process.

    Returns
    Type Description
    string

    The HTML with the path portion of each Umbraco-managed image src emptied (the query string, if present, is left in place). Tags without a data-udi attribute are unchanged.

    • View Source
    In this article
    Back to top Copyright © 2016-present Umbraco
    Generated by DocFX