Listing 1: WikiTextBlock class

public enum WikiTextBlockType
{
  Plain,
  List,
  Code
}

public class WikiTextBlock
{
  public string WikiText;
  public WikiTextBlockType BlockType;
  public WikiTextBlock(string wikitext,
    WikiTextBlockType blocktype)
  {
    this.BlockType = blocktype;
    this.WikiText = wikitext;
  }
}

Listing 2: Regex for topics

// Regex to extract topics from a line
// or the whole text like topic_text or topic_
public static string TopicRxForm 
  = @"(?<=(^|'|\s|\(|\[))"       // see A)
  + @"([A-Za-z]+)"               // see B)
  + @"([A-Za-z0-9]+)"            // see C)
  + @"(_[A-Za-z0-9]*)+";         // see D)

// A) Any match followed by beginning of the
//    line, single quote, any white space,
//    or an opening bracket: ( or [
// B) Start with any alpha character(s)
// C) Followed by any alphanumeric characters(s)
// D) Followed by an underscore "_" and
//    optionally any alphanumeric characters(s)

//Now use the string to create the Regex
public static Regex RxTopic
 = new Regex(Parser.TopicRxForm,
      RegexOptions.Compiled);

Listing 3: Create topic links

protected static void FormatTopicLinks
  (ref string line, string topic)
{
  MatchCollection wikiTopics
    = Parser.RxTopic.Matches(line);

  foreach (Match m in wikiTopics)
  {
    string matchedTopic 
	  = m.ToString().Trim();
    string lowTopic 
	  = m.ToString().Trim().ToLower();

    int revisionCount 
	  = TopicManager.RevCount[lowTopic] != null 
	  ? (int)TopicManager.RevCount[lowTopic]
      : 0;

    string showtopic 
	  = matchedTopic.Replace("_", " ");
    showtopic = showtopic.Trim();

    if(matchedTopic.ToLower() != topic.ToLower())
    {
      if(revisionCount != 0)
      {
        // topic exists, link to view.aspx
        line = Regex.Replace(line, 
          "(^|[^/>?=A-Za-z0-9])"
          + "(" + matchedTopic + ")"
          + "([^A-Z0-9a-z]|$)", 
          "$1<a href=\"view.aspx?t=$2\" "
          + "class=\"bodylink\">" 
          + showtopic 
          + "</a>$3", 
          RegexOptions.Compiled);
      }
      else
      {
        // topic does not exists, link to edit.aspx
        line = Regex.Replace(line, 
          "(^|[^/>?=A-Za-z0-9])" 
          + "(" + matchedTopic + ")"
          + "([^A-Z0-9a-z]|$)", 
          "$1<a href=\"edit.aspx?t=$2\" "
          + "title=\"create this topic\" "
          + "class=\"bodylink\">"
          + "<span class=\"nolink\">" 
          + showtopic + "</span></a>$3", 
          RegexOptions.Compiled);

        if(line == "")
          line = "a";
      }
    }
    else
    {
      // same as page topic, simple text, no link
      line = Regex.Replace(line, 
        "(^|[^/>?=A-Za-z0-9])" 
        + "(" + matchedTopic + ")"
        + "([^A-Z0-9a-z]|$)", 
        "$1" + showtopic + "$3", 
        RegexOptions.Compiled);
    }
  }
}

Additional Code...for This Article