private static string HtmlEncode(string text) { #if RESHARPER20171 return(System.Net.WebUtility.HtmlEncode(text)); #else return(RichTextBlockToHtml.HtmlEncode(text)); #endif }
private static void HandleElement(ITextControl editor, ITreeNode element, int offset) { string stringToInsert = Clipboard.GetText(); if (string.IsNullOrEmpty(stringToInsert)) { return; } IDocCommentNode docCommentNode = element as IDocCommentNode; if (docCommentNode != null) { Int32 <DocLine> currentLineNumber = editor.Document.GetCoordsByOffset(editor.Caret.Offset()).Line; string currentLine = editor.Document.GetLineText(currentLineNumber); int index = currentLine.IndexOf("///", StringComparison.Ordinal); if (index < 0) { return; } string prefix = currentLine.Substring(0, index); if (ShallEscape(docCommentNode, editor.Caret.Offset()) && RichTextBlockToHtml.HtmlEncode(stringToInsert) != stringToInsert && MessageBox.ShowYesNo("Do you want the text to be escaped?")) { stringToInsert = RichTextBlockToHtml.HtmlEncode(stringToInsert); } stringToInsert = stringToInsert.Replace("\n", "\n" + prefix + "///"); } ITokenNode token = element as ITokenNode; if (token != null) { if ((token.GetTokenType() == CSharpTokenType.STRING_LITERAL_REGULAR || token.GetTokenType() == CSharpTokenType.STRING_LITERAL_VERBATIM) && offset < token.GetTreeTextRange().EndOffset.Offset) { string text = token.GetText(); if (text.StartsWith("@") && offset > token.GetTreeTextRange().StartOffset.Offset + 1) { stringToInsert = stringToInsert.Replace("\"", "\"\""); } else if (!text.StartsWith("@")) { stringToInsert = stringToInsert. Replace("\\", "\\\\"). Replace("\a", "\\a"). Replace("\b", "\\b"). Replace("\f", "\\f"). Replace("\n", "\\n"). Replace("\r", "\\r"). Replace("\t", "\\t"). Replace("\v", "\\v"). Replace("\'", "\\'"). Replace("\"", "\\\""); } } } editor.Document.InsertText(editor.Caret.Offset(), stringToInsert); }