private void CommentHandler(MarkupParsingContext context, string commentText)
{
HtmlNodeType previousNodeType = _currentNodeType;
_currentNodeType = HtmlNodeType.Comment;
const int beginCommentLength = 4;
string processedCommentText;
bool removeComment = false;
if (_noindexCommentRegex.IsMatch(commentText))
{
// Processing of noindex comment
Match noindexCommentMatch = _noindexCommentRegex.Match(commentText);
processedCommentText = noindexCommentMatch.Groups["closingSlash"].Success ? "/noindex" : "noindex";
}
else if (KnockoutHelpers.IsEndContainerlessComment(commentText))
{
// Processing of end Knockout containerless comment
processedCommentText = "/ko";
}
else if (KnockoutHelpers.IsBeginContainerlessComment(commentText))
{
// Processing of start Knockout containerless comment
string koExpression = string.Empty;
KnockoutHelpers.ParseBeginContainerlessComment(commentText,
(localContext, expression) =>
{
SourceCodeNodeCoordinates expressionCoordinates = localContext.NodeCoordinates;
expressionCoordinates.ColumnNumber += beginCommentLength;
koExpression = _settings.MinifyKnockoutBindingExpressions ?
MinifyKnockoutBindingExpression(context, expressionCoordinates, expression) : expression;
}
);
processedCommentText = "ko " + koExpression;
}
else if (AngularHelpers.IsCommentDirective(commentText))
{
// Processing of Angular comment directive
string ngOriginalDirectiveName = string.Empty;
string ngNormalizedDirectiveName = string.Empty;
string ngExpression = string.Empty;
AngularHelpers.ParseCommentDirective(commentText,
(localContext, originalDirectiveName, normalizedDirectiveName) =>
{
ngOriginalDirectiveName = originalDirectiveName;
ngNormalizedDirectiveName = normalizedDirectiveName;
},
(localContext, expression) =>
{
SourceCodeNodeCoordinates expressionCoordinates = localContext.NodeCoordinates;
expressionCoordinates.ColumnNumber += beginCommentLength;
ngExpression = expression;
if (_settings.MinifyAngularBindingExpressions
&& ContainsAngularBindingExpression(ngNormalizedDirectiveName))
{
ngExpression = MinifyAngularBindingExpression(context, SourceCodeNodeCoordinates.Empty,
expressionCoordinates, expression);
}
}
);
processedCommentText = "directive:" + ngOriginalDirectiveName + " " + ngExpression;
}
else
{
processedCommentText = commentText;
removeComment = _settings.RemoveHtmlComments;
}
if (!removeComment)
{
_buffer.Add("<!--");
if (processedCommentText.Length > 0)
{
_buffer.Add(processedCommentText);
}
_buffer.Add("-->");
}
else
{
_currentNodeType = previousNodeType;
}
}