public string Parse(string content) { StringBuilder result = new StringBuilder(content); MatchCollection matches = CodeRegex.Matches(content); foreach (Match?match in matches) { if (match != null) { var tagKey = GetTagKey(match.Value); if (_codeResultCache.ContainsKey(match.Value)) { //Cache has it stored, so simply lookup and replace result.Replace(match.Value, _codeResultCache[match.Value]); } else if (_shortCodesIndex.ContainsKey(tagKey)) { //It is a known shortcode, so run it var shortcode = _shortCodesIndex[tagKey]; var generated = shortcode.Generate(GetArguments(match.Value)); result.Replace(match.Value, generated); //For next iteration of it's occurance cache it if it's cacheable if (shortcode.CanCacheResult) { _codeResultCache.Add(match.Value, generated); } } else if (_scriptHandler.IsKnownScript(tagKey)) { var scriptResult = _scriptHandler.ExecuteScript(tagKey, GetArguments(match.Value)); result.Replace(match.Value, scriptResult); } else { _log.Warning("Unknown shortcode or script: {0}", tagKey); } } } return(AdditionalTranslate(result.ToString())); }
public void EnsureThat_TestScriptIsKnownScript() { Assert.IsTrue(_sut.IsKnownScript("TestScript")); }