Skip to content
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

JiraLinkInlineParser.cs - Make digits in JiraKey's posible #548

Merged
merged 6 commits into from
May 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 103 additions & 23 deletions src/Markdig.Tests/Specs/JiraLinks.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class TestJiraLinks
//
// The rules for detecting a link are:
//
// - The project key must be composed of one or more capitalized ASCII letter `[A-Z]+`
// - The project key must be composed of one or more capitalized ASCII letters or digits `[A-Z,0-9]+`
// - A single hyphen `-` must separate the project key and issue number.
// - The issue number is composed of 1 or more digits `[0, 9]+`
// - The reference must be preceded by either `(` or whitespace or EOF.
Expand Down Expand Up @@ -53,13 +53,13 @@ public void JiraLinks_Example002()
// Section: Jira Links
//
// The following Markdown:
// This is a KIRA-1 issue
// This is a ABC4-123 issue
//
// Should be rendered as:
// <p>This is a <a href="http://your.company.abc/browse/KIRA-1" target="blank">KIRA-1</a> issue</p>
// <p>This is a <a href="http://your.company.abc/browse/ABC4-123" target="blank">ABC4-123</a> issue</p>

Console.WriteLine("Example 2\nSection Jira Links\n");
TestParser.TestSpec("This is a KIRA-1 issue", "<p>This is a <a href=\"http://your.company.abc/browse/KIRA-1\" target=\"blank\">KIRA-1</a> issue</p>", "jiralinks");
TestParser.TestSpec("This is a ABC4-123 issue", "<p>This is a <a href=\"http://your.company.abc/browse/ABC4-123\" target=\"blank\">ABC4-123</a> issue</p>", "jiralinks");
}

[Test]
Expand All @@ -69,20 +69,52 @@ public void JiraLinks_Example003()
// Section: Jira Links
//
// The following Markdown:
// This is a ABC45-123 issue
//
// Should be rendered as:
// <p>This is a <a href="http://your.company.abc/browse/ABC45-123" target="blank">ABC45-123</a> issue</p>

Console.WriteLine("Example 3\nSection Jira Links\n");
TestParser.TestSpec("This is a ABC45-123 issue", "<p>This is a <a href=\"http://your.company.abc/browse/ABC45-123\" target=\"blank\">ABC45-123</a> issue</p>", "jiralinks");
}

[Test]
public void JiraLinks_Example004()
{
// Example 4
// Section: Jira Links
//
// The following Markdown:
// This is a KIRA-1 issue
//
// Should be rendered as:
// <p>This is a <a href="http://your.company.abc/browse/KIRA-1" target="blank">KIRA-1</a> issue</p>

Console.WriteLine("Example 4\nSection Jira Links\n");
TestParser.TestSpec("This is a KIRA-1 issue", "<p>This is a <a href=\"http://your.company.abc/browse/KIRA-1\" target=\"blank\">KIRA-1</a> issue</p>", "jiralinks");
}

[Test]
public void JiraLinks_Example005()
{
// Example 5
// Section: Jira Links
//
// The following Markdown:
// This is a Z-1 issue
//
// Should be rendered as:
// <p>This is a <a href="http://your.company.abc/browse/Z-1" target="blank">Z-1</a> issue</p>

Console.WriteLine("Example 3\nSection Jira Links\n");
Console.WriteLine("Example 5\nSection Jira Links\n");
TestParser.TestSpec("This is a Z-1 issue", "<p>This is a <a href=\"http://your.company.abc/browse/Z-1\" target=\"blank\">Z-1</a> issue</p>", "jiralinks");
}

// These are also valid links with `(` and `)`:
[Test]
public void JiraLinks_Example004()
public void JiraLinks_Example006()
{
// Example 4
// Example 6
// Section: Jira Links
//
// The following Markdown:
Expand All @@ -91,14 +123,30 @@ public void JiraLinks_Example004()
// Should be rendered as:
// <p>This is a (<a href="http://your.company.abc/browse/ABCD-123" target="blank">ABCD-123</a>) issue</p>

Console.WriteLine("Example 4\nSection Jira Links\n");
Console.WriteLine("Example 6\nSection Jira Links\n");
TestParser.TestSpec("This is a (ABCD-123) issue", "<p>This is a (<a href=\"http://your.company.abc/browse/ABCD-123\" target=\"blank\">ABCD-123</a>) issue</p>", "jiralinks");
}

[Test]
public void JiraLinks_Example005()
public void JiraLinks_Example007()
{
// Example 5
// Example 7
// Section: Jira Links
//
// The following Markdown:
// This is a (ABC4-123) issue
//
// Should be rendered as:
// <p>This is a (<a href="http://your.company.abc/browse/ABC4-123" target="blank">ABC4-123</a>) issue</p>

Console.WriteLine("Example 7\nSection Jira Links\n");
TestParser.TestSpec("This is a (ABC4-123) issue", "<p>This is a (<a href=\"http://your.company.abc/browse/ABC4-123\" target=\"blank\">ABC4-123</a>) issue</p>", "jiralinks");
}

[Test]
public void JiraLinks_Example008()
{
// Example 8
// Section: Jira Links
//
// The following Markdown:
Expand All @@ -107,14 +155,14 @@ public void JiraLinks_Example005()
// Should be rendered as:
// <p>This is a (<a href="http://your.company.abc/browse/KIRA-1" target="blank">KIRA-1</a>) issue</p>

Console.WriteLine("Example 5\nSection Jira Links\n");
Console.WriteLine("Example 8\nSection Jira Links\n");
TestParser.TestSpec("This is a (KIRA-1) issue", "<p>This is a (<a href=\"http://your.company.abc/browse/KIRA-1\" target=\"blank\">KIRA-1</a>) issue</p>", "jiralinks");
}

[Test]
public void JiraLinks_Example006()
public void JiraLinks_Example009()
{
// Example 6
// Example 9
// Section: Jira Links
//
// The following Markdown:
Expand All @@ -123,15 +171,15 @@ public void JiraLinks_Example006()
// Should be rendered as:
// <p>This is a (<a href="http://your.company.abc/browse/Z-1" target="blank">Z-1</a>) issue</p>

Console.WriteLine("Example 6\nSection Jira Links\n");
Console.WriteLine("Example 9\nSection Jira Links\n");
TestParser.TestSpec("This is a (Z-1) issue", "<p>This is a (<a href=\"http://your.company.abc/browse/Z-1\" target=\"blank\">Z-1</a>) issue</p>", "jiralinks");
}

// These are not valid links:
[Test]
public void JiraLinks_Example007()
public void JiraLinks_Example010()
{
// Example 7
// Example 10
// Section: Jira Links
//
// The following Markdown:
Expand All @@ -140,14 +188,30 @@ public void JiraLinks_Example007()
// Should be rendered as:
// <p>This is not aJIRA-123 issue</p>

Console.WriteLine("Example 7\nSection Jira Links\n");
Console.WriteLine("Example 10\nSection Jira Links\n");
TestParser.TestSpec("This is not aJIRA-123 issue", "<p>This is not aJIRA-123 issue</p>", "jiralinks");
}

[Test]
public void JiraLinks_Example008()
public void JiraLinks_Example011()
{
// Example 8
// Example 11
// Section: Jira Links
//
// The following Markdown:
// This is not 4JIRA-123 issue
//
// Should be rendered as:
// <p>This is not 4JIRA-123 issue</p>

Console.WriteLine("Example 11\nSection Jira Links\n");
TestParser.TestSpec("This is not 4JIRA-123 issue", "<p>This is not 4JIRA-123 issue</p>", "jiralinks");
}

[Test]
public void JiraLinks_Example012()
{
// Example 12
// Section: Jira Links
//
// The following Markdown:
Expand All @@ -156,14 +220,14 @@ public void JiraLinks_Example008()
// Should be rendered as:
// <p>This is not JIRA-123a issue</p>

Console.WriteLine("Example 8\nSection Jira Links\n");
Console.WriteLine("Example 12\nSection Jira Links\n");
TestParser.TestSpec("This is not JIRA-123a issue", "<p>This is not JIRA-123a issue</p>", "jiralinks");
}

[Test]
public void JiraLinks_Example009()
public void JiraLinks_Example013()
{
// Example 9
// Example 13
// Section: Jira Links
//
// The following Markdown:
Expand All @@ -172,8 +236,24 @@ public void JiraLinks_Example009()
// Should be rendered as:
// <p>This is not JIRA- issue</p>

Console.WriteLine("Example 9\nSection Jira Links\n");
Console.WriteLine("Example 13\nSection Jira Links\n");
TestParser.TestSpec("This is not JIRA- issue", "<p>This is not JIRA- issue</p>", "jiralinks");
}

[Test]
public void JiraLinks_Example014()
{
// Example 14
// Section: Jira Links
//
// The following Markdown:
// This is not JIR4- issue
//
// Should be rendered as:
// <p>This is not JIR4- issue</p>

Console.WriteLine("Example 14\nSection Jira Links\n");
TestParser.TestSpec("This is not JIR4- issue", "<p>This is not JIR4- issue</p>", "jiralinks");
}
}
}
32 changes: 31 additions & 1 deletion src/Markdig.Tests/Specs/JiraLinks.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var pipeline = new MarkdownPipelineBuilder()

The rules for detecting a link are:

- The project key must be composed of one or more capitalized ASCII letter `[A-Z]+`
- The project key must be composed of one or more capitalized ASCII letters or digits `[A-Z,0-9]+`
- A single hyphen `-` must separate the project key and issue number.
- The issue number is composed of 1 or more digits `[0, 9]+`
- The reference must be preceded by either `(` or whitespace or EOF.
Expand All @@ -24,6 +24,18 @@ This is a ABCD-123 issue
<p>This is a <a href="http://your.company.abc/browse/ABCD-123" target="blank">ABCD-123</a> issue</p>
````````````````````````````````

```````````````````````````````` example
This is a ABC4-123 issue
.
<p>This is a <a href="http://your.company.abc/browse/ABC4-123" target="blank">ABC4-123</a> issue</p>
````````````````````````````````

```````````````````````````````` example
This is a ABC45-123 issue
.
<p>This is a <a href="http://your.company.abc/browse/ABC45-123" target="blank">ABC45-123</a> issue</p>
````````````````````````````````

```````````````````````````````` example
This is a KIRA-1 issue
.
Expand All @@ -44,6 +56,12 @@ This is a (ABCD-123) issue
<p>This is a (<a href="http://your.company.abc/browse/ABCD-123" target="blank">ABCD-123</a>) issue</p>
````````````````````````````````

```````````````````````````````` example
This is a (ABC4-123) issue
.
<p>This is a (<a href="http://your.company.abc/browse/ABC4-123" target="blank">ABC4-123</a>) issue</p>
````````````````````````````````

```````````````````````````````` example
This is a (KIRA-1) issue
.
Expand All @@ -64,6 +82,12 @@ This is not aJIRA-123 issue
<p>This is not aJIRA-123 issue</p>
````````````````````````````````

```````````````````````````````` example
This is not 4JIRA-123 issue
.
<p>This is not 4JIRA-123 issue</p>
````````````````````````````````

```````````````````````````````` example
This is not JIRA-123a issue
.
Expand All @@ -75,3 +99,9 @@ This is not JIRA- issue
.
<p>This is not JIRA- issue</p>
````````````````````````````````

```````````````````````````````` example
This is not JIR4- issue
.
<p>This is not JIR4- issue</p>
````````````````````````````````
10 changes: 8 additions & 2 deletions src/Markdig/Extensions/JiraLinks/JiraLinkInlineParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,14 @@ public override bool Match(InlineProcessor processor, ref StringSlice slice)
var startKey = slice.Start;
var endKey = slice.Start;

//read as many uppercase characters as required - project key
while (current.IsAlphaUpper())
// the first character of the key can not be a digit.
if (current.IsDigit())
{
return false;
}

// read as many uppercase characters or digits as required - project key
while (current.IsAlphaUpper() || current.IsDigit())
{
endKey = slice.Start;
current = slice.NextChar();
Expand Down