From a6e033d4c4ea5baa3f3aae128e4a27850429bc36 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Sat, 17 Aug 2019 19:02:32 +1000 Subject: [PATCH] add Bitbucket and GitLab support --- readme.md | 16 +++++++++++++--- src/Directory.Build.props | 2 +- src/MarkdownSnippets/Processing/LinkFormat.cs | 4 +++- .../Processing/SnippetMarkdownHandling.cs | 8 ++++++++ 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/readme.md b/readme.md index 837ad21e..c6e08c87 100644 --- a/readme.md +++ b/readme.md @@ -269,11 +269,13 @@ namespace MarkdownSnippets public enum LinkFormat { GitHub, - Tfs + Tfs, + Bitbucket, + GitLab } } ``` -[snippet source](/src/MarkdownSnippets/Processing/LinkFormat.cs#L1-L8) / [anchor](#snippet-LinkFormat.cs) +[snippet source](/src/MarkdownSnippets/Processing/LinkFormat.cs#L1-L10) / [anchor](#snippet-LinkFormat.cs) @@ -287,8 +289,16 @@ if (linkFormat == LinkFormat.Tfs) { return $"{path}&line={snippet.StartLine}&lineEnd={snippet.EndLine}"; } +if (linkFormat == LinkFormat.Bitbucket) +{ + return $"{path}#lines={snippet.StartLine}:{snippet.EndLine}"; +} +if (linkFormat == LinkFormat.GitLab) +{ + return $"{path}#L{snippet.StartLine}-{snippet.EndLine}"; +} ``` -[snippet source](/src/MarkdownSnippets/Processing/SnippetMarkdownHandling.cs#L72-L81) / [anchor](#snippet-buildlink) +[snippet source](/src/MarkdownSnippets/Processing/SnippetMarkdownHandling.cs#L72-L89) / [anchor](#snippet-buildlink) diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 617f2d55..36a3d34e 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -2,7 +2,7 @@ CS1591 - 16.2.0 + 16.3.0 Markdown, Snippets, mdsnippets, documentation, MarkdownSnippets Extracts snippets from code files and merges them into markdown documents. diff --git a/src/MarkdownSnippets/Processing/LinkFormat.cs b/src/MarkdownSnippets/Processing/LinkFormat.cs index 2357a6a9..7ab7ccf6 100644 --- a/src/MarkdownSnippets/Processing/LinkFormat.cs +++ b/src/MarkdownSnippets/Processing/LinkFormat.cs @@ -3,6 +3,8 @@ namespace MarkdownSnippets public enum LinkFormat { GitHub, - Tfs + Tfs, + Bitbucket, + GitLab } } \ No newline at end of file diff --git a/src/MarkdownSnippets/Processing/SnippetMarkdownHandling.cs b/src/MarkdownSnippets/Processing/SnippetMarkdownHandling.cs index dec2f6bb..d910da9f 100644 --- a/src/MarkdownSnippets/Processing/SnippetMarkdownHandling.cs +++ b/src/MarkdownSnippets/Processing/SnippetMarkdownHandling.cs @@ -78,6 +78,14 @@ string BuildLink(Snippet snippet, string path) { return $"{path}&line={snippet.StartLine}&lineEnd={snippet.EndLine}"; } + if (linkFormat == LinkFormat.Bitbucket) + { + return $"{path}#lines={snippet.StartLine}:{snippet.EndLine}"; + } + if (linkFormat == LinkFormat.GitLab) + { + return $"{path}#L{snippet.StartLine}-{snippet.EndLine}"; + } #endregion throw new Exception($"Unknown LinkFormat: {linkFormat}");