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 SourceHtmlImageSourceParser(Func<Guid, string>)
Initializes a new instance of the HtmlImageSourceParser class.
Declaration
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(IPublishedUrlProvider)
Initializes a new instance of the HtmlImageSourceParser class.
Declaration
public HtmlImageSourceParser(IPublishedUrlProvider publishedUrlProvider)
Parameters
| Type | Name | Description |
|---|---|---|
| IPublishedUrlProvider | publishedUrlProvider | The published URL provider for resolving media URLs. |
Methods
View SourceEnsureImageSources(string)
Parses the string looking for Umbraco image tags and updates them to their up-to-date image sources.
Declaration
public string EnsureImageSources(string text)
Parameters
| Type | Name | Description |
|---|---|---|
| string | text |
Returns
| Type | Description |
|---|---|
| string |
Remarks
Umbraco image tags are identified by their data-udi attributes
FindUdisFromDataAttributes(string)
Parses out media UDIs from an html string based on 'data-udi' html attributes
Declaration
public IEnumerable<Udi> FindUdisFromDataAttributes(string text)
Parameters
| Type | Name | Description |
|---|---|---|
| string | text |
Returns
| Type | Description |
|---|---|
| IEnumerable<Udi> |
RemoveImageSources(string)
Removes media URLs from <img> tags where a data-udi attribute is present
Declaration
public string RemoveImageSources(string text)
Parameters
| Type | Name | Description |
|---|---|---|
| string | text |
Returns
| Type | Description |
|---|---|
| string |