Class MacroTagParser
Parses the macro syntax in a string and renders out it's contents
Inheritance
Namespace: Umbraco.Cms.Infrastructure.Macros
Assembly: Umbraco.Infrastructure.dll
Syntax
public class MacroTagParser
Methods
View SourceFormatRichTextContentForPersistence(String)
This formats the string content posted from a rich text editor that contains macro contents to be persisted.
Declaration
public static string FormatRichTextContentForPersistence(string rteContent)
Parameters
Type | Name | Description |
---|---|---|
System.String | rteContent |
Returns
Type | Description |
---|---|
System.String |
Remarks
This is required because when editors are using the rte, the HTML that is contained in the editor might actually be displaying the entire macro content, when the data is submitted the editor will clear most of this data out but we'll still need to parse it properly and ensure the correct syntax is persisted to the db. When a macro is inserted into the rte editor, the HTML will be: {div class='umb-macro-holder'}
This could be some macro content {/div} What this method will do is remove the {div} and parse out the commented special macro syntax: {?UMBRACO_MACRO macroAlias="myMacro" /} since this is exactly how we need to persist it to the db.
FormatRichTextPersistedDataForEditor(String, IDictionary<String, String>)
This formats the persisted string to something useful for the rte so that the macro renders properly since we persist all macro formats like {?UMBRACO_MACRO macroAlias="myMacro" /}
Declaration
public static string FormatRichTextPersistedDataForEditor(string persistedContent, IDictionary<string, string> htmlAttributes)
Parameters
Type | Name | Description |
---|---|---|
System.String | persistedContent | |
IDictionary<System.String, System.String> | htmlAttributes | The HTML attributes to be added to the div |
Returns
Type | Description |
---|---|
System.String |
Remarks
This converts the persisted macro format to this: {div class='umb-macro-holder'}
{ins}Macro alias: {strong}My Macro{/strong}{/ins} {/div}
ParseMacros(String, Action<String>, Action<String, Dictionary<String, String>>)
This will accept a text block and search/parse it for macro markup. When either a text block or a a macro is found, it will call the callback method.
Declaration
public static void ParseMacros(string text, Action<string> textFoundCallback, Action<string, Dictionary<string, string>> macroFoundCallback)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | |
Action<System.String> | textFoundCallback | |
Action<System.String, Dictionary<System.String, System.String>> | macroFoundCallback |
Remarks
This method simply parses the macro contents, it does not create a string or result, this is up to the developer calling this method to implement this with the callbacks.