views:

348

answers:

2

Is there any wiki module for asp.net mvc or soemthign that can be adapted with relative ease :)

alternatively, are there any formatters for the wiki markup which perhaps implment the most common wiki markup formatting etc.

+1  A: 

try

MiniWiki

It's pretty easy to customise.

griegs
scanned through that, couldn't find info on the markup, any help on that ?
Kumar
The markup is in the code. It uses a weird notation to create a link to a new page but it works fine.I modified the code in mine to accept a better notation and it only took about an hour to understand and customise.Take a look in the file WikiToHtmlFormatter.cs in MiniWiki.DomainModel for details.
griegs
i traced the value backwards from 8 and went all the way in code to 7 but lost it somewhere along the way, perhaps if you know of the markup required to generate the <a> tag i can step through it that way
Kumar
Strangely enough that's the exact tag I modified because it made little sense to me.I no longer have the original code but from what I remember is that if you have two capital letters in the same word it made it a link to a new page.So check my next answer because i changed it so that anything enclosed in [] is an anchor link to a new or existing page.
griegs
A: 
    private void ProcessLine(string line, TextWriter writer)
    {
        int state = 0;
        int i = 0;
        int wordStart = 0;
        Action encode = () => HttpUtility.HtmlEncode(line[i].ToString(), writer);
        Func<bool> isws = () => Char.IsWhiteSpace(line[i]);

        for (i = 0; i < line.Length; ++i)
        {
            switch (state)
            {
                case 0:
                    if (line[i] == '*')
                    {
                        state = 1;
                    }
                    else if (line[i] == '/')
                    {
                        state = 4;
                    }
                    else if (line[i] == '[')
                    {
                        wordStart = i + 1;
                        state = 7;
                    }
                    else
                    {
                        encode();
                    }
                    break;

                case 1: //Start bold
                    if (isws())
                    {
                        encode();
                        state = 0;
                    }
                    else
                    {
                        writer.Write("<b>");
                        encode();
                        state = 2;
                    }
                    break;

                case 2: //End bold
                    if (isws())
                    {
                        encode();
                        state = 3;
                    }
                    else if (line[i] == '*')
                    {
                        writer.Write("</b>");
                        state = 0;
                    }
                    else
                    {
                        encode();
                    }
                    break;

                case 3:
                    if (isws())
                    {
                        encode();
                    }
                    else
                    {
                        encode();
                        state = 2;
                    }
                    break;

                case 4: //Start italics
                    if (isws())
                    {
                        HttpUtility.HtmlEncode("/ ", writer);
                        state = 0;
                    }
                    else
                    {
                        writer.Write("<i>");
                        encode();
                        state = 5;
                    }
                    break;

                case 5: //End italics
                    if (isws())
                    {
                        encode();
                        state = 6;
                    }
                    else if (line[i] == '/')
                    {
                        writer.Write("</i>");
                        state = 0;
                    }
                    else
                    {
                        encode();
                    }
                    break;

                case 6:
                    if (isws())
                    {
                        encode();
                    }
                    else
                    {
                        encode();
                        state = 5;
                    }
                    break;

                case 7: //Start link
                    state = 8;
                    break;
                case 8: //End link
                    if (line[i] == ']')
                    {
                        WriteLink(line.Substring(wordStart, i - wordStart), writer);
                        state = 0;
                    }
                    break;
            }
        }

        // Clean up italics, bold etc. based on the state we were in at the end of the line.
        switch (state)
        {
            case 0:
                break;
            case 1:
                HttpUtility.HtmlEncode("*", writer);
                break;
            case 2:
            case 3:
                writer.Write("</b>");
                break;
            case 4:
                HttpUtility.HtmlEncode("/", writer);
                break;
            case 5:
            case 6:
                writer.Write("</i>");
                break;
            case 7:
                HttpUtility.HtmlEncode(line.Substring(wordStart), writer);
                break;
            case 8:
                WriteLink(line.Substring(wordStart), writer);
                break;
        }

    }
griegs
The above code changes the behaviour such that anything enclosed in [] is made a link to a new or existing page.Hope this is what you were after Kumar.
griegs