Skip to content

Commit ee60648

Browse files
author
maximv
committed
fixed: #4 Ability to remove specific lines from the md output
updating the extension for the v1.2.0
1 parent d724ad6 commit ee60648

12 files changed

+84
-37
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
is_global = true
2+
build_property.TargetFramework =
3+
build_property.TargetPlatformMinVersion =
4+
build_property.UsingMicrosoftNETSdkWeb =
5+
build_property.ProjectTypeGuids = {82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
6+
build_property.PublishSingleFile =
7+
build_property.IncludeAllContentForSelfExtract =
8+
build_property._SupportedPlatformList =

CsToMd/CsToMd.cs

+24-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace CsToMd
1919
[CodeGeneratorRegistration(typeof(CsToMd), nameof(CsToMd), ContextGuidEmbraced, GeneratesDesignTimeSource = true)]
2020
public sealed class CsToMd : IVsSingleFileGenerator
2121
{
22-
const string _defaultConfigFileName = "cstomd.config";
22+
public const string DefaultConfigFileName = "cstomd.config";
2323

2424
public const string PackageGuid = "5a4dc0a7-5ae0-42a4-8d38-326644b59f10";
2525
public const string ContextGuidEmbraced = "{FAE04EC1-301F-11D3-BF4B-00C04F79EFBC}";
@@ -62,12 +62,33 @@ public int Generate(string wszInputFilePath, string bstrInputFileContents,
6262
{
6363
var inputLines = bstrInputFileContents.Split(new[] { NewLine }, StringSplitOptions.None);
6464

65+
var inputDir = Path.GetDirectoryName(wszInputFilePath);
66+
// ReSharper disable once AssignNullToNotNullAttribute
67+
var defaultConfigFilePath = Path.Combine(inputDir, DefaultConfigFileName);
68+
69+
string configReadError = null;
6570
string[] removeLineStartingWith = null;
66-
if (File.Exists(_defaultConfigFileName))
67-
removeLineStartingWith = File.ReadAllLines(_defaultConfigFileName);
71+
if (File.Exists(defaultConfigFilePath))
72+
{
73+
try
74+
{
75+
removeLineStartingWith = File.ReadAllLines(defaultConfigFilePath);
76+
}
77+
catch (Exception ex)
78+
{
79+
configReadError = $"Unable to read '{defaultConfigFilePath}' with error: '{ex.Message}'";
80+
}
81+
}
6882

6983
var outputBuilder = CommentStripper.StripMdComments(inputLines, removeLineStartingWith);
7084

85+
if (configReadError != null)
86+
{
87+
outputBuilder.AppendLine("### There are errors while producing the markdown document file");
88+
outputBuilder.AppendLine();
89+
outputBuilder.AppendLine(configReadError);
90+
}
91+
7192
var output = outputBuilder.ToString();
7293
var outputBytes = Encoding.UTF8.GetBytes(output);
7394
var outputByteCount = outputBytes.Length;

CsToMd/CsToMd.csproj

+11-4
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
<Reference Include="Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
122122
<HintPath>..\packages\Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime.14.3.26930\lib\net20\Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime.dll</HintPath>
123123
<EmbedInteropTypes>True</EmbedInteropTypes>
124+
<Private>True</Private>
124125
</Reference>
125126
<Reference Include="Microsoft.VisualStudio.OLE.Interop, Version=7.1.40304.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
126127
<HintPath>..\packages\Microsoft.VisualStudio.OLE.Interop.7.10.6071\lib\Microsoft.VisualStudio.OLE.Interop.dll</HintPath>
@@ -137,26 +138,32 @@
137138
<Reference Include="Microsoft.VisualStudio.Shell.Interop.10.0, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
138139
<HintPath>..\packages\Microsoft.VisualStudio.Shell.Interop.10.0.10.0.30320\lib\net20\Microsoft.VisualStudio.Shell.Interop.10.0.dll</HintPath>
139140
<EmbedInteropTypes>True</EmbedInteropTypes>
141+
<Private>True</Private>
140142
</Reference>
141143
<Reference Include="Microsoft.VisualStudio.Shell.Interop.11.0, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
142144
<HintPath>..\packages\Microsoft.VisualStudio.Shell.Interop.11.0.11.0.61031\lib\net20\Microsoft.VisualStudio.Shell.Interop.11.0.dll</HintPath>
143145
<EmbedInteropTypes>True</EmbedInteropTypes>
146+
<Private>True</Private>
144147
</Reference>
145148
<Reference Include="Microsoft.VisualStudio.Shell.Interop.12.0, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
146149
<HintPath>..\packages\Microsoft.VisualStudio.Shell.Interop.12.0.12.0.30111\lib\net20\Microsoft.VisualStudio.Shell.Interop.12.0.dll</HintPath>
147150
<EmbedInteropTypes>True</EmbedInteropTypes>
151+
<Private>True</Private>
148152
</Reference>
149153
<Reference Include="Microsoft.VisualStudio.Shell.Interop.14.0.DesignTime, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
150154
<HintPath>..\packages\Microsoft.VisualStudio.Shell.Interop.14.0.DesignTime.14.3.26929\lib\net20\Microsoft.VisualStudio.Shell.Interop.14.0.DesignTime.dll</HintPath>
151155
<EmbedInteropTypes>True</EmbedInteropTypes>
156+
<Private>True</Private>
152157
</Reference>
153158
<Reference Include="Microsoft.VisualStudio.Shell.Interop.15.3.DesignTime, Version=15.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
154159
<HintPath>..\packages\Microsoft.VisualStudio.Shell.Interop.15.3.DesignTime.15.0.26929\lib\net20\Microsoft.VisualStudio.Shell.Interop.15.3.DesignTime.dll</HintPath>
155160
<EmbedInteropTypes>True</EmbedInteropTypes>
161+
<Private>True</Private>
156162
</Reference>
157163
<Reference Include="Microsoft.VisualStudio.Shell.Interop.15.6.DesignTime, Version=15.6.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
158164
<HintPath>..\packages\Microsoft.VisualStudio.Shell.Interop.15.6.DesignTime.15.6.27413\lib\net20\Microsoft.VisualStudio.Shell.Interop.15.6.DesignTime.dll</HintPath>
159165
<EmbedInteropTypes>True</EmbedInteropTypes>
166+
<Private>True</Private>
160167
</Reference>
161168
<Reference Include="Microsoft.VisualStudio.Shell.Interop.8.0, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
162169
<HintPath>..\packages\Microsoft.VisualStudio.Shell.Interop.8.0.8.0.50728\lib\net11\Microsoft.VisualStudio.Shell.Interop.8.0.dll</HintPath>
@@ -291,17 +298,17 @@
291298
<PropertyGroup>
292299
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
293300
</PropertyGroup>
294-
<Error Condition="!Exists('..\packages\Microsoft.VisualStudio.SDK.EmbedInteropTypes.15.0.27\build\Microsoft.VisualStudio.SDK.EmbedInteropTypes.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.VisualStudio.SDK.EmbedInteropTypes.15.0.27\build\Microsoft.VisualStudio.SDK.EmbedInteropTypes.targets'))" />
295-
<Error Condition="!Exists('..\packages\Microsoft.VisualStudio.Threading.Analyzers.16.4.33\build\Microsoft.VisualStudio.Threading.Analyzers.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.VisualStudio.Threading.Analyzers.16.4.33\build\Microsoft.VisualStudio.Threading.Analyzers.targets'))" />
296-
<Error Condition="!Exists('..\packages\Microsoft.VisualStudio.SDK.Analyzers.16.3.14\build\Microsoft.VisualStudio.SDK.Analyzers.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.VisualStudio.SDK.Analyzers.16.3.14\build\Microsoft.VisualStudio.SDK.Analyzers.targets'))" />
297301
<Error Condition="!Exists('..\packages\Microsoft.VSSDK.BuildTools.16.5.5\build\Microsoft.VSSDK.BuildTools.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.VSSDK.BuildTools.16.5.5\build\Microsoft.VSSDK.BuildTools.props'))" />
298302
<Error Condition="!Exists('..\packages\Microsoft.VSSDK.BuildTools.16.5.5\build\Microsoft.VSSDK.BuildTools.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.VSSDK.BuildTools.16.5.5\build\Microsoft.VSSDK.BuildTools.targets'))" />
299303
<Error Condition="!Exists('..\packages\Microsoft.CodeAnalysis.BannedApiAnalyzers.2.9.7\build\Microsoft.CodeAnalysis.BannedApiAnalyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeAnalysis.BannedApiAnalyzers.2.9.7\build\Microsoft.CodeAnalysis.BannedApiAnalyzers.props'))" />
304+
<Error Condition="!Exists('..\packages\Microsoft.VisualStudio.SDK.EmbedInteropTypes.15.0.27\build\Microsoft.VisualStudio.SDK.EmbedInteropTypes.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.VisualStudio.SDK.EmbedInteropTypes.15.0.27\build\Microsoft.VisualStudio.SDK.EmbedInteropTypes.targets'))" />
305+
<Error Condition="!Exists('..\packages\Microsoft.VisualStudio.Threading.Analyzers.16.4.33\build\Microsoft.VisualStudio.Threading.Analyzers.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.VisualStudio.Threading.Analyzers.16.4.33\build\Microsoft.VisualStudio.Threading.Analyzers.targets'))" />
306+
<Error Condition="!Exists('..\packages\Microsoft.VisualStudio.SDK.Analyzers.16.3.14\build\Microsoft.VisualStudio.SDK.Analyzers.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.VisualStudio.SDK.Analyzers.16.3.14\build\Microsoft.VisualStudio.SDK.Analyzers.targets'))" />
300307
</Target>
308+
<Import Project="..\packages\Microsoft.VSSDK.BuildTools.16.5.5\build\Microsoft.VSSDK.BuildTools.targets" Condition="Exists('..\packages\Microsoft.VSSDK.BuildTools.16.5.5\build\Microsoft.VSSDK.BuildTools.targets')" />
301309
<Import Project="..\packages\Microsoft.VisualStudio.SDK.EmbedInteropTypes.15.0.27\build\Microsoft.VisualStudio.SDK.EmbedInteropTypes.targets" Condition="Exists('..\packages\Microsoft.VisualStudio.SDK.EmbedInteropTypes.15.0.27\build\Microsoft.VisualStudio.SDK.EmbedInteropTypes.targets')" />
302310
<Import Project="..\packages\Microsoft.VisualStudio.Threading.Analyzers.16.4.33\build\Microsoft.VisualStudio.Threading.Analyzers.targets" Condition="Exists('..\packages\Microsoft.VisualStudio.Threading.Analyzers.16.4.33\build\Microsoft.VisualStudio.Threading.Analyzers.targets')" />
303311
<Import Project="..\packages\Microsoft.VisualStudio.SDK.Analyzers.16.3.14\build\Microsoft.VisualStudio.SDK.Analyzers.targets" Condition="Exists('..\packages\Microsoft.VisualStudio.SDK.Analyzers.16.3.14\build\Microsoft.VisualStudio.SDK.Analyzers.targets')" />
304-
<Import Project="..\packages\Microsoft.VSSDK.BuildTools.16.5.5\build\Microsoft.VSSDK.BuildTools.targets" Condition="Exists('..\packages\Microsoft.VSSDK.BuildTools.16.5.5\build\Microsoft.VSSDK.BuildTools.targets')" />
305312
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
306313
Other similar extension points exist, see Microsoft.Common.targets.
307314
<Target Name="BeforeBuild">

CsToMd/LICENSE.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018 Maksim Volkau
3+
Copyright (c) 2018-2020 Maksim Volkau
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

CsToMd/Properties/AssemblyInfo.cs

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
using System.Reflection;
2-
using System.Runtime.CompilerServices;
32
using System.Runtime.InteropServices;
43

54
// General Information about an assembly is controlled through the following
65
// set of attributes. Change these attribute values to modify the information
76
// associated with an assembly.
8-
[assembly: AssemblyTitle("CsToMd")]
9-
[assembly: AssemblyDescription("")]
10-
[assembly: AssemblyConfiguration("")]
11-
[assembly: AssemblyCompany("")]
127
[assembly: AssemblyProduct("CsToMd")]
13-
[assembly: AssemblyCopyright("")]
14-
[assembly: AssemblyTrademark("")]
15-
[assembly: AssemblyCulture("")]
8+
[assembly: AssemblyCopyright("Copyright (c) 2018-2020 Maksim Volkau")]
169

1710
// Setting ComVisible to false makes the types in this assembly not visible
1811
// to COM components. If you need to access a type in this assembly from
@@ -28,5 +21,5 @@
2821
//
2922
// You can specify all the values or you can default the Build and Revision Numbers
3023
// by using the '*' as shown below:
31-
[assembly: AssemblyVersion("1.1.0.0")]
32-
[assembly: AssemblyFileVersion("1.1.0.0")]
24+
[assembly: AssemblyVersion("1.2.0.0")]
25+
[assembly: AssemblyFileVersion("1.2.0.0")]

CsToMd/ReleaseNotes.txt

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Release Notes
22

3-
## V1.1.1
4-
5-
Added support for Visual Studio 2019 (v16)
3+
## v1.2.0 - Feature release
64

5+
- added: #3 Make it to dotnet CLI tool (dotnet-cstomd)
6+
- added: #4 Ability to remove specific lines from the md output #4
7+
- added: #6 Add the special comments to wrap the section into collapsible details enhancement
8+
- added: #7 Strip the comment from the line with `//md` enhancement

CsToMd/packages.config

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<package id="Microsoft.VisualStudio.ImageCatalog" version="16.3.29316.127" targetFramework="net472" />
77
<package id="Microsoft.VisualStudio.Imaging" version="16.3.29318.209" targetFramework="net472" />
88
<package id="Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime" version="14.3.26930" targetFramework="net472" />
9-
<package id="Microsoft.VisualStudio.OLE.Interop" version="7.10.6071" targetFramework="net461" />
9+
<package id="Microsoft.VisualStudio.OLE.Interop" version="7.10.6071" targetFramework="net472" />
1010
<package id="Microsoft.VisualStudio.SDK.Analyzers" version="16.3.14" targetFramework="net472" />
1111
<package id="Microsoft.VisualStudio.SDK.EmbedInteropTypes" version="15.0.27" targetFramework="net472" />
1212
<package id="Microsoft.VisualStudio.Shell.15.0" version="16.3.29318.209" targetFramework="net472" />

CsToMd/source.extension.vsixmanifest

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
33
<Metadata>
4-
<Identity Id="CsToMd.13e98d61-1f50-4acd-8e25-099cf4b733f3" Version="1.1.1" Language="en-US" Publisher="dadhi" />
4+
<Identity Id="CsToMd.13e98d61-1f50-4acd-8e25-099cf4b733f3" Version="1.2.0" Language="en-US" Publisher="dadhi" />
55
<DisplayName>CsToMd</DisplayName>
66
<Description xml:space="preserve">Generates a Markdown .md file from the input C# .cs file removing the `/*md` and `md*/` comment lines</Description>
77
<MoreInfo>https://github.com/dadhi/Cstomd</MoreInfo>

CsToMdTest/CsToMdTest.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
<Compile Include="Properties\AssemblyInfo.cs" />
5050
</ItemGroup>
5151
<ItemGroup>
52+
<None Include="cstomd.config" />
5253
<None Include="NiceDoc.md">
5354
<AutoGen>True</AutoGen>
5455
<DesignTime>True</DesignTime>

CsToMdTest/NiceDoc.cs

+14-7
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,24 @@
33
44
> Hmm, why?
55
6-
*Because it is.*
6+
*Why not* and here is the proof
7+
md*/
8+
//md{ collapsible section with using(s) ...
9+
//md```
10+
using System;
11+
using System.Text;
12+
//md```
13+
//md}
714

8-
Here is the proof __below__
15+
//- removed comment
916

10-
```cs md*/
11-
public class Class1
17+
//md```cs
18+
public class Foo
1219
{
13-
public void Blah() { }
20+
public void Bar() { }
1421
}
1522
/*md
1623
```
17-
18-
End of nice document.
24+
//md ~~stripped comment~~
25+
End of the nice document.
1926
md*/

CsToMdTest/NiceDoc.md

+13-7
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@
22

33
> Hmm, why?
44
5-
*Because it is.*
5+
*Why not* and here is the proof
6+
<details><summary><strong>collapsible section with using(s) ...</strong></summary>
67

7-
Here is the proof __below__
8+
```
9+
using System;
10+
using System.Text;
11+
```
12+
</details>
813

9-
```cs
10-
public class Class1
14+
15+
```cs
16+
public class Foo
1117
{
12-
public void Blah() { }
18+
public void Bar() { }
1319
}
1420
```
15-
16-
End of nice document.
21+
~~stripped comment~~
22+
End of the nice document.

CsToMdTest/cstomd.config

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
//-
2+

0 commit comments

Comments
 (0)