-
Notifications
You must be signed in to change notification settings - Fork 868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support multiple region selection in code snippet #246
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,13 +84,13 @@ Block file inclusion must be in a single line and with no prefix characters befo | |
User may need to define section. Mostly used for code table. | ||
Give an example below. | ||
|
||
> [!div class="tabbedCodeSnippets" data-resources="OutlookServices.Calendar"] | ||
> ```cs | ||
> <cs code text> | ||
> ``` | ||
> ```javascript | ||
> <js code text> | ||
> ``` | ||
[!div class="tabbedCodeSnippets" data-resources="OutlookServices.Calendar"] | ||
```cs | ||
<cs code text> | ||
``` | ||
```javascript | ||
<js code text> | ||
``` | ||
|
||
The above blockquote Markdown text will transform to section html as in the following: | ||
``` | ||
|
@@ -110,8 +110,12 @@ Allows you to insert code with code language specified. The content of specified | |
* __`<language>`__ can be made up of any number of character and '-'. However, the recommended value should follow [Highlight.js language names and aliases](http://highlightjs.readthedocs.org/en/latest/css-classes-reference.html#language-names-and-aliases). | ||
* __`<codepath>`__ is the relative path in file system which indicates the code snippet file that you want to expand. | ||
* __`<queryoption>`__ and __`<queryoptionvalue>`__ are used together to retrieve part of the code snippet file in the line range or tag name way. We have 2 query string options to represent these two ways: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 3 query string options? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2 option: |
||
* __`#`__: _`#L{startlinenumber}-L{endlinenumber}`_ (line range) or _`#L{tagname}`_ (tag name) | ||
* __`?`__: _`?start={startlinenumber}&end={endlinenumber}`_ (line range) or _`?{name}={tagname}`_ (tag name) | ||
|
||
| | query string using `#` | query string using `?` | ||
|--------------------------|----------------------------------------|------------- | ||
| 1. line range | `#L{startlinenumber}-L{endlinenumber}` | `?start={startlinenumber}&end={endlinenumber}` | ||
| 2. tagname | `#{tagname}` | `?name={tagname}` | ||
| 3. multiple region range | _Unsupported_ | `?range={rangequerystring}` | ||
* __`<title>`__ can be omitted. | ||
|
||
#### Code Snippet Sample | ||
|
@@ -123,6 +127,7 @@ Allows you to insert code with code language specified. The content of specified | |
|
||
[!code[Main](index.xml?start=5&end=9)] | ||
[!code-javascript[Main](../jquery.js?name=testsnippet)] | ||
[!code[Main](index.xml?range=2,5-7,9-) "This includes the lines 2, 5, 6, 7 and lines 9 to the last line"] | ||
``` | ||
|
||
#### Tag Name Representation in Code Snippet Source File | ||
|
Large diffs are not rendered by default.
This file was deleted.
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; | ||
} | ||
|
||
} | ||
} |
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); | ||
} | ||
} |
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]; | ||
} | ||
} | ||
} | ||
} |
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]; | ||
} | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
div should be in blocks? why removing
>