在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):SimonCropp/MarkdownSnippets开源软件地址(OpenSource Url):https://github.com/SimonCropp/MarkdownSnippets开源编程语言(OpenSource Language):C# 99.9%开源软件介绍(OpenSource Introduction):MarkdownSnippetsA dotnet tool that extract snippets from code files and merges them into markdown documents. .net 5 or .net 6 is required to run this tool. Value PropositionAutomatically extract snippets from code and injecting them into markdown documents has several benefits:
Behavior
InstallationEnsure dotnet CLI is installed. Install MarkdownSnippets.Tool dotnet tool install -g MarkdownSnippets.Tool Usagemdsnippets C:\Code\TargetDirectory If no directory is passed the current directory will be used, but only if it exists with a git repository directory tree. If not an error is returned. Document ConventionThere are two approaches scanning and modifying markdown files. SourceTransformThis is the default. source.md fileThe file convention recursively scans the target directory for all mdsource directoryThere is a secondary convention that leverages the use of a directory named When using the InPlaceOverwriteRecursively scans the target directory for all Command linemdsnippets -c InPlaceOverwrite mdsnippets --convention InPlaceOverwrite Config fileCan be enabled in mdsnippets.json config file. {
"Convention": "InPlaceOverwrite"
} Moving from SourceTransform to InPlaceOverwrite
Mark resulting files as read onlyTo mark the resulting documents files as read only use This can be helpful in preventing incorrectly editing the documents file instead of the mdsnippets -r true mdsnippets --read-only true Defining SnippetsAny code wrapped in a convention based comment will be picked up. The comment needs to start with
Named C# regions will also be picked up, with the name of the region used as the key. To stop regions collapsing in Visual Studio disable 'enter outlining mode when files open'. See Visual Studio outlining. UrlsAsSnippetsUrls to files to be included as snippets. Space Each url will be accessible using the file name as a key. Any snippets within the files will be extracted and accessible as individual keyed snippets. mdsnippets --urls-as-snippets "https://github.com/SimonCropp/MarkdownSnippets/snippet.cs" mdsnippets -u "https://github.com/SimonCropp/MarkdownSnippets/snippet.cs" Using SnippetsThe keyed snippets can be used in any documentation Then snippets with that key. For example Some blurb about the below snippet snippet: MySnippetName The resulting markdown will be:
Notes:
Including a snippet from the webSnippets that start with
Will render:
Files are downloaded to Including a full fileIf no snippet is found matching the defined name. The target directory will be searched for a file matching that name. For example:
Will render:
Files are downloaded to LinkFormatDefines the format of Command linemdsnippets --link-format Bitbucket mdsnippets -l Bitbucket Valuesnamespace MarkdownSnippets;
public enum LinkFormat
{
GitHub,
Tfs,
Bitbucket,
GitLab,
None
} Link format OmitSnippetLinksThe links below a snippet can be omitted. Command linemdsnippets --omit-snippet-links true Config file
How links are constructedif (linkFormat == LinkFormat.GitHub)
{
return $"{path}#L{snippet.StartLine}-L{snippet.EndLine}";
}
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}";
} UrlPrefixUrlPrefix allows a string to be defined that will prefix all snippet links. This is helpful when the markdown file are being hosted on a site that is no co-located with the source code files. It can be defined in the config file, the MsBuild task, and the dotnet tool. Command linemdsnippets --url-prefix "TheUrlPrefix" Config file
Add to Windows ExplorerUse src/context-menu.reg to add MarkdownSnippets to the Windows Explorer context menu. Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\Shell]
@="none"
[HKEY_CLASSES_ROOT\Directory\shell\mdsnippets]
"MUIVerb"="run mdsnippets"
"Position"="bottom"
[HKEY_CLASSES_ROOT\Directory\Background\shell\mdsnippets]
"MUIVerb"="run mdsnippets"
"Position"="bottom"
[HKEY_CLASSES_ROOT\Directory\shell\mdsnippets\command]
@="cmd.exe /c mdsnippets \"%V\""
[HKEY_CLASSES_ROOT\Directory\Background\shell\mdsnippets\command]
@="cmd.exe /c mdsnippets \"%V\"" More Documentation
CreditsLoosely based on some code from https://github.com/shiftkey/scribble. IconDown by Alfredo Creates from The Noun Project. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论