diff --git a/src/Markdig.Tests/Specs/JiraLinks.md b/src/Markdig.Tests/Specs/JiraLinks.md index f8ef6215..a618e96b 100644 --- a/src/Markdig.Tests/Specs/JiraLinks.md +++ b/src/Markdig.Tests/Specs/JiraLinks.md @@ -4,21 +4,74 @@ The JiraLinks extension will automatically add links to JIRA issue items within ``` var pipeline = new MarkdownPipelineBuilder() - .UseJiraLinks(new JiraLinkOptions() - { - Url = "https://company.atlassian.net" - }) + .UseJiraLinks(new JiraLinkOptions("http://your.company.abc")) .Build(); ``` -The project key must be capitalised for the link to be detected, it can be any length. The following are valid examples. +The rules for detecting a link are: -* EG-123 -* TEST-123 -* DIG-123 +- The project key must be composed of onre or more capitalised ASCII letter `[A-Z]+` +- A single hypen `-` must separate the project key and issue number. +- The issue number is composed of 1 or more digits `[0, 9]+` +- The reference must be preceeded by either `(` or whitespace or EOF. +- The reference must be followed by either `)` or whitespace or EOF. -A single hypen must separate the project key and issue number. The issue number can be any length. +The following are valid examples: -The reference must be preceeded by either nothing or whitespace. +```````````````````````````````` example +This is a ABCD-123 issue +. +
This is a ABCD-123 issue
+```````````````````````````````` -The reference must be followed by either nothing or whitespace. \ No newline at end of file +```````````````````````````````` example +This is a KIRA-1 issue +. +This is a KIRA-1 issue
+```````````````````````````````` + +```````````````````````````````` example +This is a Z-1 issue +. +This is a Z-1 issue
+```````````````````````````````` + +These are also valid links with `(` and `)`: + +```````````````````````````````` example +This is a (ABCD-123) issue +. +This is a (ABCD-123) issue
+```````````````````````````````` + +```````````````````````````````` example +This is a (KIRA-1) issue +. +This is a (KIRA-1) issue
+```````````````````````````````` + +```````````````````````````````` example +This is a (Z-1) issue +. +This is a (Z-1) issue
+```````````````````````````````` + +These are not valid links: + +```````````````````````````````` example +This is not aJIRA-123 issue +. +This is not aJIRA-123 issue
+```````````````````````````````` + +```````````````````````````````` example +This is not JIRA-123a issue +. +This is not JIRA-123a issue
+```````````````````````````````` + +```````````````````````````````` example +This is not JIRA- issue +. +This is not JIRA- issue
+```````````````````````````````` diff --git a/src/Markdig.Tests/Specs/Specs.cs b/src/Markdig.Tests/Specs/Specs.cs index ccda17a5..6dedfb0a 100644 --- a/src/Markdig.Tests/Specs/Specs.cs +++ b/src/Markdig.Tests/Specs/Specs.cs @@ -20529,4 +20529,196 @@ namespace Markdig.Tests TestParser.TestSpec("Check **http://www.a.com** or __http://www.b.com__", "Check http://www.a.com or http://www.b.com
", "autolinks|advanced"); } } + // ## Jira Links + // + // The JiraLinks extension will automatically add links to JIRA issue items within your markdown, e.g. XX-1234. For this to happen, you must configure the extension when adding to the pipeline, e.g. + // + // ``` + // var pipeline = new MarkdownPipelineBuilder() + // .UseJiraLinks(new JiraLinkOptions("http://your.company.abc")) + // .Build(); + // ``` + // + // The rules for detecting a link are: + // + // - The project key must be composed of onre or more capitalised ASCII letter `[A-Z]+` + // - A single hypen `-` must separate the project key and issue number. + // - The issue number is composed of 1 or more digits `[0, 9]+` + // - The reference must be preceeded by either `(` or whitespace or EOF. + // - The reference must be followed by either `)` or whitespace or EOF. + // + // The following are valid examples: + [TestFixture] + public partial class TestJiraLinks + { + [Test] + public void Example001() + { + // Example 1 + // Section: Jira Links + // + // The following CommonMark: + // This is a ABCD-123 issue + // + // Should be rendered as: + //This is a ABCD-123 issue
+ + Console.WriteLine("Example {0}" + Environment.NewLine + "Section: {0}" + Environment.NewLine, 1, " Jira Links"); + TestParser.TestSpec("This is a ABCD-123 issue", "This is a ABCD-123 issue
", "jiralinks"); + } + } + [TestFixture] + public partial class TestJiraLinks + { + [Test] + public void Example002() + { + // Example 2 + // Section: Jira Links + // + // The following CommonMark: + // This is a KIRA-1 issue + // + // Should be rendered as: + //This is a KIRA-1 issue
+ + Console.WriteLine("Example {0}" + Environment.NewLine + "Section: {0}" + Environment.NewLine, 2, " Jira Links"); + TestParser.TestSpec("This is a KIRA-1 issue", "This is a KIRA-1 issue
", "jiralinks"); + } + } + [TestFixture] + public partial class TestJiraLinks + { + [Test] + public void Example003() + { + // Example 3 + // Section: Jira Links + // + // The following CommonMark: + // This is a Z-1 issue + // + // Should be rendered as: + //This is a Z-1 issue
+ + Console.WriteLine("Example {0}" + Environment.NewLine + "Section: {0}" + Environment.NewLine, 3, " Jira Links"); + TestParser.TestSpec("This is a Z-1 issue", "This is a Z-1 issue
", "jiralinks"); + } + } + // These are also valid links with `(` and `)`: + [TestFixture] + public partial class TestJiraLinks + { + [Test] + public void Example004() + { + // Example 4 + // Section: Jira Links + // + // The following CommonMark: + // This is a (ABCD-123) issue + // + // Should be rendered as: + //This is a (ABCD-123) issue
+ + Console.WriteLine("Example {0}" + Environment.NewLine + "Section: {0}" + Environment.NewLine, 4, " Jira Links"); + TestParser.TestSpec("This is a (ABCD-123) issue", "This is a (ABCD-123) issue
", "jiralinks"); + } + } + [TestFixture] + public partial class TestJiraLinks + { + [Test] + public void Example005() + { + // Example 5 + // Section: Jira Links + // + // The following CommonMark: + // This is a (KIRA-1) issue + // + // Should be rendered as: + //This is a (KIRA-1) issue
+ + Console.WriteLine("Example {0}" + Environment.NewLine + "Section: {0}" + Environment.NewLine, 5, " Jira Links"); + TestParser.TestSpec("This is a (KIRA-1) issue", "This is a (KIRA-1) issue
", "jiralinks"); + } + } + [TestFixture] + public partial class TestJiraLinks + { + [Test] + public void Example006() + { + // Example 6 + // Section: Jira Links + // + // The following CommonMark: + // This is a (Z-1) issue + // + // Should be rendered as: + //This is a (Z-1) issue
+ + Console.WriteLine("Example {0}" + Environment.NewLine + "Section: {0}" + Environment.NewLine, 6, " Jira Links"); + TestParser.TestSpec("This is a (Z-1) issue", "This is a (Z-1) issue
", "jiralinks"); + } + } + // These are not valid links: + [TestFixture] + public partial class TestJiraLinks + { + [Test] + public void Example007() + { + // Example 7 + // Section: Jira Links + // + // The following CommonMark: + // This is not aJIRA-123 issue + // + // Should be rendered as: + //This is not aJIRA-123 issue
+ + Console.WriteLine("Example {0}" + Environment.NewLine + "Section: {0}" + Environment.NewLine, 7, " Jira Links"); + TestParser.TestSpec("This is not aJIRA-123 issue", "This is not aJIRA-123 issue
", "jiralinks"); + } + } + [TestFixture] + public partial class TestJiraLinks + { + [Test] + public void Example008() + { + // Example 8 + // Section: Jira Links + // + // The following CommonMark: + // This is not JIRA-123a issue + // + // Should be rendered as: + //This is not JIRA-123a issue
+ + Console.WriteLine("Example {0}" + Environment.NewLine + "Section: {0}" + Environment.NewLine, 8, " Jira Links"); + TestParser.TestSpec("This is not JIRA-123a issue", "This is not JIRA-123a issue
", "jiralinks"); + } + } + [TestFixture] + public partial class TestJiraLinks + { + [Test] + public void Example009() + { + // Example 9 + // Section: Jira Links + // + // The following CommonMark: + // This is not JIRA- issue + // + // Should be rendered as: + //This is not JIRA- issue
+ + Console.WriteLine("Example {0}" + Environment.NewLine + "Section: {0}" + Environment.NewLine, 9, " Jira Links"); + TestParser.TestSpec("This is not JIRA- issue", "This is not JIRA- issue
", "jiralinks"); + } + } } diff --git a/src/Markdig.Tests/Specs/Specs.tt b/src/Markdig.Tests/Specs/Specs.tt index 95efac0f..893204ad 100644 --- a/src/Markdig.Tests/Specs/Specs.tt +++ b/src/Markdig.Tests/Specs/Specs.tt @@ -61,6 +61,7 @@ SOFTWARE. new KeyValuePair