Skip to content

Commit

Permalink
Merge pull request #243 from ansyral/221
Browse files Browse the repository at this point in the history
fix #221
  • Loading branch information
ansyral committed Apr 7, 2016
2 parents df55f9d + 6c89564 commit 2609ae0
Showing 1 changed file with 7 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class TripleSlashCommentModel
{
private const string idSelector = @"((?![0-9])[\w_])+[\w\(\)\.\{\}\[\]\|\*\^~#@!`,_<>:]*";
private static Regex CommentIdRegex = new Regex(@"^(?<type>N|T|M|P|F|E):(?<id>" + idSelector + ")$", RegexOptions.Compiled);
private readonly string[] _lines;

private readonly ITripleSlashCommentParserContext _context;

Expand All @@ -48,7 +47,6 @@ private TripleSlashCommentModel(string xml, ITripleSlashCommentParserContext con
ResolveParameterRef(doc);
}
var nav = doc.CreateNavigator();
_lines = doc.ToString().Split('\n');
Summary = GetSummary(nav, context);
Remarks = GetRemarks(nav, context);
Returns = GetReturns(nav, context);
Expand Down Expand Up @@ -287,9 +285,8 @@ private void ResolveCrefLink(XNode node, string nodeSelector, Action<string> add

try
{

var nodes = node.XPathSelectElements(nodeSelector + "[@cref]").ToList();
foreach(var item in nodes)
foreach (var item in nodes)
{
var value = item.Attribute("cref").Value;
// Strict check is needed as value could be an invalid href,
Expand Down Expand Up @@ -385,7 +382,7 @@ private string GetSingleNodeValue(XPathNavigator nav, string selector)
return output;
}
}

/// <summary>
/// For multiple line comments, comment start position always aligns with its node tag's start position
/// </summary>
Expand All @@ -397,10 +394,11 @@ private string GetXmlValue(XPathNavigator node)
// e.g.
// <remarks><para>Value</para></remarks>
// decode InnerXml as it encodes
// IXmlLineInfo.LinePosition starts from 1 and it would ignore '<'
// e.g.
// <summary/> the LinePosition is the column number of 's', so it should be minus 2
var lineInfo = node as IXmlLineInfo;
var lineNumber = lineInfo.LineNumber - 1;
var line = _lines[lineNumber];
int column = GetNonWhitespaceIndex(line);
int column = lineInfo.HasLineInfo() ? lineInfo.LinePosition - 2 : 0;

var content = WebUtility.HtmlDecode(node.InnerXml);
var lines = GetLines(content, column);
Expand All @@ -422,19 +420,13 @@ private static string NormalizeLine(string line, int column)
{
int trimIndex = Math.Min(column, GetNonWhitespaceIndex(line));

// special handle for \r
if (trimIndex > 0 && line[trimIndex - 1] == '\r')
{
trimIndex--;
}

return line.Substring(trimIndex);
}

private static int GetNonWhitespaceIndex(string line)
{
int index = 0;
while (index < line.Length && char.IsWhiteSpace(line[index]))
while (index < line.Length && char.IsWhiteSpace(line[index]) && line[index] != '\r')
{
index++;
}
Expand Down

0 comments on commit 2609ae0

Please sign in to comment.