Exemplo n.º 1
0
        private string wikiBehaviorMatch(Match match)
        {
            string replacement = match.ToString();
            string linestart = match.Groups["LineStart"].Value;
            string lineend = match.Groups["LineEnd"].Value;
            string expr = match.Groups["Behavior"].Value;
            match = null;

            bool doBehavior = false;
            if (insideTable.IsMatch(linestart))
            {
                doBehavior = true;
            }
            else if (!preBehavior.IsMatch(linestart))
            {
                doBehavior = true;
            }

            if (doBehavior)
            {
                TopicContext tc = new TopicContext(_fed, _mgr, new TopicVersionInfo(_fed, _behaviorTopic));
                BehaviorInterpreter interpreter = new BehaviorInterpreter(_behaviorTopic == null ? "" : _behaviorTopic.DottedName, expr, _fed, _fed.WikiTalkVersion, this);
                if (!interpreter.Parse())
                {   //parse failed
                    replacement = ErrorMessage(null, interpreter.ErrorString);
                }
                else
                {   //parse succeeded
                    if (!interpreter.EvaluateToPresentation(tc, _mgr.ExternalReferences))
                    {   //eval failed
                        replacement = ErrorMessage(null, interpreter.ErrorString);
                        _processBehaviorToText = false;
                    }
                    else
                    {   //eval succeeded
                        WikiOutput nOut = new WomDocument(null);
                        interpreter.Value.OutputTo(nOut);
                        replacement = nOut.ToString();
                    }

                }
                if (replacement.Contains("<script"))
                {
                    replacement = Regex.Replace(replacement, @"<script(.*?)>", @"&lt;script$1&gt;", RegexOptions.Singleline);
                    replacement = Regex.Replace(replacement, @"</script>", @"&lt;/script&gt;");
                }
                replacement = Regex.Replace(replacement, @"^\|\|", "||}", RegexOptions.Multiline);
                replacement = Regex.Replace(replacement, @" \|\|$| \|\|\r\n| \{\|\|\r\n|\|\|\r\n", " {||\r\n", RegexOptions.Multiline);
                replacement = Regex.Replace(replacement, @"(?<!\{|"""")\|\|(?!\}|"""")", @" {||}");
                if (_processBehaviorToText)
                {
                    replacement = replacement.Replace("        ", "\t");
                    replacement = escAmpersand.Replace(replacement, "&amp;"); //full escape causes some pages to fail
                    replacement = ProcessText(replacement, _behaviorTopic, _mgr, true, 350).ParsedDocument;
                }
            }
            replacement = linestart + replacement + lineend;
            return replacement;
        }
Exemplo n.º 2
0
 public string ErrorMessage(string title, string body)
 {
     // We can't use the fancy ErrorString method -- it didn't exist in v0
     WikiOutput nOut = new WomDocument(null);
     nOut.WriteErrorMessage(title, body);
     return nOut.ToString();
 }