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

Option to omit only the source link #489

Merged
merged 1 commit into from
May 25, 2022
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
5 changes: 3 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,11 @@ public enum LinkFormat
GitHub,
Tfs,
Bitbucket,
GitLab
GitLab,
None
}
```
<sup><a href='/src/MarkdownSnippets/Processing/LinkFormat.cs#L1-L9' title='Snippet source file'>snippet source</a> | <a href='#snippet-LinkFormat.cs' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/MarkdownSnippets/Processing/LinkFormat.cs#L1-L10' title='Snippet source file'>snippet source</a> | <a href='#snippet-LinkFormat.cs' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand Down
2 changes: 2 additions & 0 deletions readme.source.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ mdsnippets --omit-snippet-links true

snippet: LinkFormat.cs

Link format `None` will omit the source link but still keep the snippet anchor.


#### How links are constructed

Expand Down
3 changes: 2 additions & 1 deletion schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"Tfs",
"GitHub",
"Bitbucket",
"GitLab"
"GitLab",
"None"
],
"pattern": "^.*$"
},
Expand Down
3 changes: 2 additions & 1 deletion src/MarkdownSnippets/Processing/LinkFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ public enum LinkFormat
GitHub,
Tfs,
Bitbucket,
GitLab
GitLab,
None
}
6 changes: 3 additions & 3 deletions src/MarkdownSnippets/Processing/SnippetMarkdownHandling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public SnippetMarkdownHandling(string targetDirectory, LinkFormat linkFormat, bo

if (hashSnippetAnchors)
{
getAnchorId = ComputeId;
getAnchorId = ComputeId;
}
else
{
Expand Down Expand Up @@ -68,7 +68,7 @@ string GetAnchorText(Snippet snippet, uint index)
return id;
}

return $"{id}-{index}";
return $"{id}-{index}";
}

static string ComputeId(Snippet snippet)
Expand All @@ -81,7 +81,7 @@ static string ComputeId(Snippet snippet)
string GetSupText(Snippet snippet, string anchor)
{
var linkForAnchor = $"<a href='#{anchor}' title='Start of snippet'>anchor</a>";
if (snippet.Path == null)
if (snippet.Path == null || linkFormat == LinkFormat.None)
{
return linkForAnchor;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<a id='snippet-thekey'></a>
```thelanguage
theValue
```
<sup><a href='#snippet-thekey' title='Start of snippet'>anchor</a></sup>
16 changes: 15 additions & 1 deletion src/Tests/SnippetMarkdownHandlingTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using MarkdownSnippets;
using MarkdownSnippets;

[UsesVerify]
public class SnippetMarkdownHandlingTests
Expand All @@ -17,6 +17,20 @@ public Task Append()
return Verify(builder.ToString());
}

[Fact]
public Task AppendOmitSourceLink()
{
var builder = new StringBuilder();
var snippets = Snippets();
var markdownHandling = new SnippetMarkdownHandling("c:/dir/", LinkFormat.None, false, false);
using (var writer = new StringWriter(builder))
{
markdownHandling.Append("key1", snippets, writer.WriteLine);
}

return Verify(builder.ToString());
}

[Fact]
public Task AppendOmitSnippetLinks()
{
Expand Down