Class HtmlImageSourceParser
Utility class used to parse and update image sources in HTML content based on Umbraco media references.
Inheritance
Namespace: Umbraco.Cms.Core.Templates
Assembly: Umbraco.Core.dll
Syntax
public sealed class HtmlImageSourceParser
Constructors
View SourceHtmlImageSourceParser(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. |
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. |
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. |
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 SourceEnsureImageSources(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 |
Remarks
Umbraco image tags are identified by their data-udi attributes.
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 |
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 |