我试图解析文本格式。我想标记内联代码,就像SO一样,用反引号(`
)。规则应该是,如果你想在内联代码元素中使用反引号,你应该在内联代码中使用双反引号。文本解析 - 我的解析器跳过命令
这样的:
`反引号与`标记内嵌代码(`)``
我的解析器似乎双反引号完全跳过出于某种原因。继承人的,因为该内嵌代码解析函数的代码:
private string ParseInlineCode(string input)
{
for (int i = 0; i < input.Length; i++)
{
if (input[i] == '`' && input[i - 1] != '\\')
{
if (input[i + 1] == '`')
{
string str = ReadToCharacter('`', i + 2, input);
while (input[i + str.Length + 2] != '`')
{
str += ReadToCharacter('`', i + str.Length + 3, input);
}
string tbr = "``" + str + "``";
str = str.Replace("&", "&");
str = str.Replace("<", "<");
str = str.Replace(">", ">");
input = input.Replace(tbr, "<code>" + str + "</code>");
i += str.Length + 13;
}
else
{
string str = ReadToCharacter('`', i + 1, input);
input = input.Replace("`" + str + "`", "<code>" + str + "</code>");
i += str.Length + 13;
}
}
}
return input;
}
如果我使用的东西左右单反引号,它正确地将其包装在<code>
标签。
RegEx更适合这份工作吗? – Propeng 2010-05-25 19:21:02