Skip to content

Commit

Permalink
Fixed bug which caused invalid line breaks at sections/functions #3
Browse files Browse the repository at this point in the history
  • Loading branch information
TwentyFourMinutes committed Nov 21, 2020
1 parent a325271 commit b3fb55e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
16 changes: 12 additions & 4 deletions src/RazorMinifier/RazorMinifier.Core/Minifiers/CSHtmlMinifier.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using PreMailer.Net;
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using PreMailer.Net;

namespace RazorMinifier.Core.Minifiers
{
Expand Down Expand Up @@ -77,14 +77,22 @@ private static (string, MinifyResult) Minify(string input, bool usePreMailer)

input = _emptyLineRegex.Replace(input, string.Empty);

var indexOffset = 0;

foreach (Match match in _razorSectionRegex.Matches(input))
{
input = input.Insert(match.Index, Environment.NewLine);
input = input.Insert(match.Index + indexOffset, Environment.NewLine);

indexOffset += Environment.NewLine.Length;
}

indexOffset = 0;

foreach (Match match in _razorFunctionsRegex.Matches(input))
{
input = input.Insert(match.Index, Environment.NewLine);
input = input.Insert(match.Index + indexOffset, Environment.NewLine);

indexOffset += Environment.NewLine.Length;
}

foreach (var header in headers)
Expand Down
18 changes: 9 additions & 9 deletions src/RazorMinifier/RazorMinifier/RazorMinifier.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
using DulcisX.Core;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using DulcisX.Core;
using DulcisX.Core.Enums;
using DulcisX.Core.Enums.VisualStudio;
using DulcisX.Nodes;
Expand All @@ -10,14 +18,6 @@
using RazorMinifier.Core.Minifiers;
using RazorMinifier.Models;
using RazorMinifier.Models.Enums;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Task = System.Threading.Tasks.Task;

namespace RazorMinifier.VSIX
Expand Down
8 changes: 4 additions & 4 deletions src/RazorMinifier/RazorMinifier/ToggleRazorMinifier.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using DulcisX.Nodes;
using Microsoft.VisualStudio.Shell;
using RazorMinifier.Models.Enums;
using System;
using System;
using System.ComponentModel.Design;
using System.IO;
using System.Linq;
using DulcisX.Nodes;
using Microsoft.VisualStudio.Shell;
using RazorMinifier.Models.Enums;
using Task = System.Threading.Tasks.Task;

namespace RazorMinifier.VSIX
Expand Down

0 comments on commit b3fb55e

Please sign in to comment.