Search Results for

    Show / Hide Table of Contents

    Class MacroTagParser

    Parses the macro syntax in a string and renders out it's contents

    Inheritance
    System.Object
    Namespace: Umbraco.Cms.Infrastructure.Macros
    Assembly: cs.temp.dll.dll
    Syntax
    public class MacroTagParser

    Methods

    FormatRichTextContentForPersistence(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=&quot;myMacro&quot; /}

    Declaration
    public static string FormatRichTextPersistedDataForEditor(string persistedContent, IDictionary<string, string> htmlAttributes)
    Parameters
    Type Name Description
    System.String persistedContent
    System.Collections.Generic.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
    System.Action<System.String> textFoundCallback
    System.Action<System.String, System.Collections.Generic.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.

    In This Article
    • Methods
      • FormatRichTextContentForPersistence(String)
      • FormatRichTextPersistedDataForEditor(String, IDictionary<String, String>)
      • ParseMacros(String, Action<String>, Action<String, Dictionary<String, String>>)
    Back to top Copyright © 2016-present Umbraco
    Generated by DocFX