public static string Format(string text, CodeCommentOptions options) { var xml = XElement.Parse(string.Format("<doc>{0}</doc>", text)); var line = new CommentLineXml(xml, options); var regex = CodeCommentHelper.GetCommentRegex("CSharp", false); var formatter = new CommentFormatter(line, string.Empty, options, regex); return formatter.ToString(); }
public static string Format(string text, string prefix) { var xml = XElement.Parse($"<doc>{text}</doc>"); var line = new CommentLineXml(xml); var regex = CodeCommentHelper.GetCommentRegex(CodeLanguage.CSharp, !string.IsNullOrEmpty(prefix)); var formatter = new CommentFormatter(line, prefix, 4, regex); return formatter.ToString(); }
public static string Format(string text, CodeCommentOptions options) { var xml = XElement.Parse(string.Format("<doc>{0}</doc>", text)); var line = new CommentLineXml(xml, options); var regex = CodeCommentHelper.GetCommentRegex("CSharp", false); var formatter = new CommentFormatter(line, string.Empty, options, regex); return(formatter.ToString()); }
public static string Format(string text, string prefix) { var xml = XElement.Parse($"<doc>{text}</doc>"); var line = new CommentLineXml(xml); var regex = CodeCommentHelper.GetCommentRegex(CodeLanguage.CSharp, !string.IsNullOrEmpty(prefix)); var formatter = new CommentFormatter(line, prefix, 4, regex); return(formatter.ToString()); }
/// <summary> /// Helper function to generate the preview in the options menu. /// </summary> public static string FormatXml(string text) { var xml = XElement.Parse($"<doc>{text}</doc>"); var line = new CommentLineXml(xml); var regex = CodeCommentHelper.GetCommentRegex(CodeLanguage.CSharp, false); var formatter = new CommentFormatter(line, "///", 4, regex); return formatter.ToString(); }
/// <summary> /// Formats the comment. /// </summary> /// <param name="options">The options to be used for formatting.</param> public TextPoint Format(CodeCommentOptions options) { if (!IsValid) { throw new InvalidOperationException("Cannot format comment, the comment is not valid."); } var originalText = _startPoint.GetText(_endPoint); var matches = _commentLineRegex.Matches(originalText).OfType<Match>().ToArray(); var commentPrefix = matches.First(m => m.Success).Groups["prefix"].Value; // Concatenate the comment lines without comment prefixes and see if the resulting bit // can be parsed as XML. ICommentLine line = null; var lineTexts = matches.Select(m => m.Groups["line"].Value).ToArray(); var commentText = string.Join(Environment.NewLine, lineTexts); if (commentText.Contains('<')) { try { var xml = XElement.Parse(string.Format("<doc>{0}</doc>", commentText)); line = new CommentLineXml(xml, options); } catch (System.Xml.XmlException) { // If XML cannot be parsed, comment will be handled as a normal text comment. } } if (line == null) { line = new CommentLine(commentText); } var formatter = new CommentFormatter( line, commentPrefix, options, CodeCommentHelper.GetCommentRegex(_document.Language, false)); if (!formatter.Equals(originalText)) { var cursor = StartPoint.CreateEditPoint(); cursor.Delete(EndPoint); cursor.Insert(formatter.ToString()); _endPoint = cursor.CreateEditPoint(); } return EndPoint; }
/// <summary> /// Helper function to generate the preview in the options menu. /// </summary> public static string FormatXml(string text) { var xml = XElement.Parse(string.Format("<doc>{0}</doc>", text)); var line = new CommentLineXml(xml); var regex = CodeCommentHelper.GetCommentRegex("CSharp", false); var formatter = new CommentFormatter(line, "///", 4, regex); return formatter.ToString(); }