<commit_before>﻿using Umbraco.Core;
using Archetype.Umbraco.Models;

namespace Archetype.Umbraco.Extensions
{
    public static class Extensions
    {
        //lifted from the core as it is marked 'internal'
        public static bool DetectIsJson(this string input)
        {
            input = input.Trim();
            return input.StartsWith("{") && input.EndsWith("}")
                   || input.StartsWith("[") && input.EndsWith("]");
        }

        public static bool IsArchetype(this Property prop)
        {
            return prop.PropertyEditorAlias.InvariantEquals(Constants.PropertyEditorAlias);
        }
    }
}
<commit_msg>Use an extension to parse the RTE macros into rendered macros<commit_after>﻿using System;
using System.Web;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using Umbraco.Core;
using Umbraco.Web;
using Archetype.Umbraco.Models;

namespace Archetype.Umbraco.Extensions
{
    public static class Extensions
    {
        //lifted from the core as it is marked 'internal'
        public static bool DetectIsJson(this string input)
        {
            input = input.Trim();
            return input.StartsWith("{") && input.EndsWith("}")
                   || input.StartsWith("[") && input.EndsWith("]");
        }

        public static bool IsArchetype(this Property prop)
        {
            return prop.PropertyEditorAlias.InvariantEquals(Constants.PropertyEditorAlias);
        }

        public static HtmlString ParseMacros(this string input, UmbracoHelper umbHelper)
        {
            var regex = new Regex("(<div class=\".*umb-macro-holder.*\".*macroAlias=\"(\\w*)\"(.*)\\/>.*\\/div>)");
            var match = regex.Match(input);

            while (match.Success)
            {
                var parms = match.Groups[3].ToString().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                var dictionary = new Dictionary<string, object>();
                foreach (var parm in parms)
                {
                    var thisParm = parm.Split(new string[] { "=" }, StringSplitOptions.RemoveEmptyEntries);
                    dictionary.Add(thisParm[0], thisParm[1].Substring(1, thisParm[1].Length - 2));
                }

                input = input.Replace(match.Groups[0].ToString(), umbHelper.RenderMacro(match.Groups[2].ToString(), dictionary).ToHtmlString());
                match = regex.Match(input);
            }

            return new HtmlString(input);
        }
    }
}

{'fraction_non_alphanumeric': 0.12118811881188118, 'fraction_numerical': 0.0031683168316831685, 'mean_word_length': 2.250965250965251, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3430883', 'n_tokens_mistral': 707, 'n_tokens_neox': 683, 'n_words': 153}