-
Notifications
You must be signed in to change notification settings - Fork 866
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support multiple region selection in code snippet #189
- Loading branch information
1 parent
c783135
commit 3888915
Showing
15 changed files
with
487 additions
and
319 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
src/Microsoft.DocAsCode.Dfm/DfmFencesBlockPathQueryOption.cs
This file was deleted.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
src/Microsoft.DocAsCode.Dfm/DfmFencesBlockPathQueryOptions/DfmFencesBlockPathQueryOption.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Microsoft.DocAsCode.Dfm | ||
{ | ||
using System.Collections.Generic; | ||
|
||
public abstract class DfmFencesBlockPathQueryOption : IDfmFencesBlockPathQueryOption | ||
{ | ||
public string ErrorMessage { get; protected set; } | ||
|
||
public abstract bool ValidateAndPrepare(string[] lines, DfmFencesBlockToken token); | ||
|
||
public abstract IEnumerable<string> GetQueryLines(string[] lines); | ||
|
||
protected bool CheckLineRange(int totalLines, int? startLine, int? endLine) | ||
{ | ||
if (startLine == null && endLine == null) | ||
{ | ||
ErrorMessage = "Neither start line nor end line is specified correctly"; | ||
return false; | ||
} | ||
|
||
if (startLine <= 0 || endLine <= 0) | ||
{ | ||
ErrorMessage = "Start/End line should be larger than zero"; | ||
return false; | ||
} | ||
|
||
if (startLine > endLine) | ||
{ | ||
ErrorMessage = $"Start line {startLine} shouldn't be larger than end line {endLine}"; | ||
return false; | ||
} | ||
|
||
if (startLine > totalLines) | ||
{ | ||
ErrorMessage = $"Start line '{startLine}' execeeds total file lines '{totalLines}'"; | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/Microsoft.DocAsCode.Dfm/DfmFencesBlockPathQueryOptions/IDfmFencesBlockPathQueryOption.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Microsoft.DocAsCode.Dfm | ||
{ | ||
using System.Collections.Generic; | ||
|
||
public interface IDfmFencesBlockPathQueryOption | ||
{ | ||
string ErrorMessage { get; } | ||
|
||
bool ValidateAndPrepare(string[] lines, DfmFencesBlockToken token); | ||
|
||
IEnumerable<string> GetQueryLines(string[] lines); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/Microsoft.DocAsCode.Dfm/DfmFencesBlockPathQueryOptions/LineRangeBlockPathQueryOption.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Microsoft.DocAsCode.Dfm | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
class LineRangeBlockPathQueryOption : DfmFencesBlockPathQueryOption | ||
{ | ||
public int? StartLine { get; set; } | ||
|
||
public int? EndLine { get; set; } | ||
|
||
public override bool ValidateAndPrepare(string[] lines, DfmFencesBlockToken token) | ||
{ | ||
if (!CheckLineRange(lines.Length, StartLine, EndLine)) | ||
{ | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public override IEnumerable<string> GetQueryLines(string[] lines) | ||
{ | ||
int startLine = StartLine ?? 1; | ||
int endLine = EndLine ?? lines.Length; | ||
|
||
for (int i = startLine; i <= Math.Min(endLine, lines.Length); i++) | ||
{ | ||
yield return lines[i - 1]; | ||
} | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...oft.DocAsCode.Dfm/DfmFencesBlockPathQueryOptions/MultipleLineRangeBlockPathQueryOption.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Microsoft.DocAsCode.Dfm | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
class MultipleLineRangeBlockPathQueryOption : DfmFencesBlockPathQueryOption | ||
{ | ||
public List<Tuple<int?, int?>> LinePairs { get; set; } = new List<Tuple<int?, int?>>(); | ||
|
||
public override bool ValidateAndPrepare(string[] lines, DfmFencesBlockToken token) | ||
{ | ||
foreach (var pair in LinePairs) | ||
{ | ||
if (!CheckLineRange(lines.Length, pair.Item1, pair.Item2)) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public override IEnumerable<string> GetQueryLines(string[] lines) | ||
{ | ||
foreach (var pair in LinePairs) | ||
{ | ||
int startLine = pair.Item1 ?? 1; | ||
int endLine = pair.Item2 ?? lines.Length; | ||
|
||
for (int i = startLine; i <= Math.Min(endLine, lines.Length); i++) | ||
{ | ||
yield return lines[i - 1]; | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.