From 0c71f4f520f1915e405d113dd4774264c9f415fa Mon Sep 17 00:00:00 2001 From: Ajay Bhargav Baaskaran Date: Wed, 5 Dec 2018 11:48:33 -0800 Subject: [PATCH] Added test for razor comment between code block and markup (dotnet/aspnetcore-tooling#14) \n\nCommit migrated from https://github.com/dotnet/aspnetcore-tooling/commit/131003d0c33ea0f4cae0c5bb20ada98dbf54e272 --- .../src/Legacy/HtmlMarkupParser.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Legacy/HtmlMarkupParser.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Legacy/HtmlMarkupParser.cs index a30d5b2de1..9d7400dd11 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Legacy/HtmlMarkupParser.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Legacy/HtmlMarkupParser.cs @@ -798,6 +798,21 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy private void ParseRazorCommentWithLeadingAndTrailingWhitespace(in SyntaxListBuilder builder) { + if (Context.NullGenerateWhitespaceAndNewLine) + { + // Usually this is set to true when a Code block ends and there is whitespace left after it. + // We don't want to write it to output. + Context.NullGenerateWhitespaceAndNewLine = false; + SpanContext.ChunkGenerator = SpanChunkGenerator.Null; + AcceptWhile(IsSpacingToken(includeNewLines: false)); + if (At(SyntaxKind.NewLine)) + { + AcceptAndMoveNext(); + } + + builder.Add(OutputAsMarkupEphemeralLiteral()); + } + var shouldRenderWhitespace = true; var lastWhitespace = AcceptWhitespaceInLines(); var startOfLine = Context.StartOfLine;