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.
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.
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;
}
}