Is there any way to generate a Escaped Markup text

Mar 22, 2012 at 3:35 PM

I am looking for a neat way to search for all potential Markup sequences that happen to be in a string and wrap them in Escaped Markup tags.  Is this already built into the engine? 

I imagine this could be done with regular expression, not that I'm great at it... 

It could also be done by performing a search and replace... 

But it's almost as these methods don't seem like the right approach.  Shouldn't it be the engine that performs this task, as it is the engine that knows all of the markups?

 

Coordinator
Mar 22, 2012 at 4:04 PM

What you could do, is just use the Parser and send in your string. That will allow you to get instances of all scopes that are used for regular rendering. At which point, you can do what you wish, as each scope returns it's index in the string. Does that work?

Mar 22, 2012 at 5:50 PM

I think so, I probably should have spent more time and dug into code before posting.  As my solution is rather obvious now.

But I was thinking more along these lines... 

Create a new Renderer see below.    And then call the IWikiEngine.Render method with my new renderer.  Right now the EscapeRenderer is vary basic, and I think this might be sufficient for my needs. 

 

 

    /// <summary>
    /// This class will render all other renderer(s) Registered with <see cref="Renderers"/>
    /// as an Escape sequence
    /// </summary>
    public class EscapeRenderer : IRenderer
    {
        private string _RendererId;
      
        public string Id
        {
            get
            {
                if (string.IsNullOrEmpty(_RendererId))
                    _RendererId = GetType().Name.Replace("Renderer", string.Empty);

                return _RendererId;
            }
        }

        public bool CanExpand(string scopeName)
        {
            return true;
        }

        public string Expand(string scopeName, string input, Func<string, string> htmlEncode, Func<string, string> attributeEncode)
        {
            return "{\"" + input + "\")";
        }
    }