private static string FilterWikiMarkup(string line)
{
Regex commentRE = new Regex(@"\[{2}(File|Файл|Image|Изображение|Category|Категория):(.+?)(\|.+)?(\]{2})?$");
string comment = line;
comment = comment.Replace("{{", "<nowiki>{{").Replace("}}", "}}</nowiki>").Replace("'''", "").Replace("''", "").Trim();
comment = comment.Replace("<ref>", "<nowiki><ref>").Replace("</ref>", "</ref></nowiki>");
comment = comment.Replace("<!--", "<nowiki><!--").Replace("-->", "--></nowiki>");
comment = commentRE.Replace(comment, "<nowiki>[[</nowiki>[[:$1:$2]]<nowiki>$3]]</nowiki>");
if (comment.Contains("<nowiki>"))
{
for (int index = comment.IndexOf("<nowiki>");
index != -1;
index = comment.IndexOf("<nowiki>", index + 1))
{
int endIndex = comment.IndexOf("</nowiki>", index);
if (endIndex == -1)
{
comment += "</nowiki>";
break;
}
}
}
return comment;
}