Skip to content

Commit

Permalink
fixed: #4 Ability to remove specific lines from the md output
Browse files Browse the repository at this point in the history
updating the extension for the v1.2.0
  • Loading branch information
maximv committed Aug 28, 2020
1 parent d724ad6 commit ee60648
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 37 deletions.
8 changes: 8 additions & 0 deletions CsToMd/CsToMd.GeneratedMSBuildEditorConfig.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
is_global = true
build_property.TargetFramework =
build_property.TargetPlatformMinVersion =
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids = {82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
build_property.PublishSingleFile =
build_property.IncludeAllContentForSelfExtract =
build_property._SupportedPlatformList =
27 changes: 24 additions & 3 deletions CsToMd/CsToMd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace CsToMd
[CodeGeneratorRegistration(typeof(CsToMd), nameof(CsToMd), ContextGuidEmbraced, GeneratesDesignTimeSource = true)]
public sealed class CsToMd : IVsSingleFileGenerator
{
const string _defaultConfigFileName = "cstomd.config";
public const string DefaultConfigFileName = "cstomd.config";

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

var inputDir = Path.GetDirectoryName(wszInputFilePath);
// ReSharper disable once AssignNullToNotNullAttribute
var defaultConfigFilePath = Path.Combine(inputDir, DefaultConfigFileName);

string configReadError = null;
string[] removeLineStartingWith = null;
if (File.Exists(_defaultConfigFileName))
removeLineStartingWith = File.ReadAllLines(_defaultConfigFileName);
if (File.Exists(defaultConfigFilePath))
{
try
{
removeLineStartingWith = File.ReadAllLines(defaultConfigFilePath);
}
catch (Exception ex)
{
configReadError = $"Unable to read '{defaultConfigFilePath}' with error: '{ex.Message}'";
}
}

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

if (configReadError != null)
{
outputBuilder.AppendLine("### There are errors while producing the markdown document file");
outputBuilder.AppendLine();
outputBuilder.AppendLine(configReadError);
}

var output = outputBuilder.ToString();
var outputBytes = Encoding.UTF8.GetBytes(output);
var outputByteCount = outputBytes.Length;
Expand Down
15 changes: 11 additions & 4 deletions CsToMd/CsToMd.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
<Reference Include="Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime.14.3.26930\lib\net20\Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.OLE.Interop, Version=7.1.40304.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<HintPath>..\packages\Microsoft.VisualStudio.OLE.Interop.7.10.6071\lib\Microsoft.VisualStudio.OLE.Interop.dll</HintPath>
Expand All @@ -137,26 +138,32 @@
<Reference Include="Microsoft.VisualStudio.Shell.Interop.10.0, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.VisualStudio.Shell.Interop.10.0.10.0.30320\lib\net20\Microsoft.VisualStudio.Shell.Interop.10.0.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.Shell.Interop.11.0, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.VisualStudio.Shell.Interop.11.0.11.0.61031\lib\net20\Microsoft.VisualStudio.Shell.Interop.11.0.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.Shell.Interop.12.0, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.VisualStudio.Shell.Interop.12.0.12.0.30111\lib\net20\Microsoft.VisualStudio.Shell.Interop.12.0.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.Shell.Interop.14.0.DesignTime, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.VisualStudio.Shell.Interop.14.0.DesignTime.14.3.26929\lib\net20\Microsoft.VisualStudio.Shell.Interop.14.0.DesignTime.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.Shell.Interop.15.3.DesignTime, Version=15.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.VisualStudio.Shell.Interop.15.3.DesignTime.15.0.26929\lib\net20\Microsoft.VisualStudio.Shell.Interop.15.3.DesignTime.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.Shell.Interop.15.6.DesignTime, Version=15.6.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.VisualStudio.Shell.Interop.15.6.DesignTime.15.6.27413\lib\net20\Microsoft.VisualStudio.Shell.Interop.15.6.DesignTime.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.Shell.Interop.8.0, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<HintPath>..\packages\Microsoft.VisualStudio.Shell.Interop.8.0.8.0.50728\lib\net11\Microsoft.VisualStudio.Shell.Interop.8.0.dll</HintPath>
Expand Down Expand Up @@ -291,17 +298,17 @@
<PropertyGroup>
<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>
</PropertyGroup>
<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'))" />
<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'))" />
<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'))" />
<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'))" />
<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'))" />
<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'))" />
<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'))" />
<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'))" />
<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'))" />
</Target>
<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')" />
<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')" />
<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')" />
<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')" />
<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')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
2 changes: 1 addition & 1 deletion CsToMd/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 Maksim Volkau
Copyright (c) 2018-2020 Maksim Volkau

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
13 changes: 3 additions & 10 deletions CsToMd/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("CsToMd")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CsToMd")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyCopyright("Copyright (c) 2018-2020 Maksim Volkau")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
Expand All @@ -28,5 +21,5 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]
8 changes: 5 additions & 3 deletions CsToMd/ReleaseNotes.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Release Notes

## V1.1.1

Added support for Visual Studio 2019 (v16)
## v1.2.0 - Feature release

- added: #3 Make it to dotnet CLI tool (dotnet-cstomd)
- added: #4 Ability to remove specific lines from the md output #4
- added: #6 Add the special comments to wrap the section into collapsible details enhancement
- added: #7 Strip the comment from the line with `//md` enhancement
2 changes: 1 addition & 1 deletion CsToMd/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<package id="Microsoft.VisualStudio.ImageCatalog" version="16.3.29316.127" targetFramework="net472" />
<package id="Microsoft.VisualStudio.Imaging" version="16.3.29318.209" targetFramework="net472" />
<package id="Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime" version="14.3.26930" targetFramework="net472" />
<package id="Microsoft.VisualStudio.OLE.Interop" version="7.10.6071" targetFramework="net461" />
<package id="Microsoft.VisualStudio.OLE.Interop" version="7.10.6071" targetFramework="net472" />
<package id="Microsoft.VisualStudio.SDK.Analyzers" version="16.3.14" targetFramework="net472" />
<package id="Microsoft.VisualStudio.SDK.EmbedInteropTypes" version="15.0.27" targetFramework="net472" />
<package id="Microsoft.VisualStudio.Shell.15.0" version="16.3.29318.209" targetFramework="net472" />
Expand Down
2 changes: 1 addition & 1 deletion CsToMd/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<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">
<Metadata>
<Identity Id="CsToMd.13e98d61-1f50-4acd-8e25-099cf4b733f3" Version="1.1.1" Language="en-US" Publisher="dadhi" />
<Identity Id="CsToMd.13e98d61-1f50-4acd-8e25-099cf4b733f3" Version="1.2.0" Language="en-US" Publisher="dadhi" />
<DisplayName>CsToMd</DisplayName>
<Description xml:space="preserve">Generates a Markdown .md file from the input C# .cs file removing the `/*md` and `md*/` comment lines</Description>
<MoreInfo>https://github.com/dadhi/Cstomd</MoreInfo>
Expand Down
1 change: 1 addition & 0 deletions CsToMdTest/CsToMdTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="cstomd.config" />
<None Include="NiceDoc.md">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
Expand Down
21 changes: 14 additions & 7 deletions CsToMdTest/NiceDoc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,24 @@
> Hmm, why?
*Because it is.*
*Why not* and here is the proof
md*/
//md{ collapsible section with using(s) ...
//md```
using System;
using System.Text;
//md```
//md}

Here is the proof __below__
//- removed comment

```cs md*/
public class Class1
//md```cs
public class Foo
{
public void Blah() { }
public void Bar() { }
}
/*md
```
End of nice document.
//md ~~stripped comment~~
End of the nice document.
md*/
20 changes: 13 additions & 7 deletions CsToMdTest/NiceDoc.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@

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

Here is the proof __below__
```
using System;
using System.Text;
```
</details>

```cs
public class Class1

```cs
public class Foo
{
public void Blah() { }
public void Bar() { }
}
```

End of nice document.
~~stripped comment~~
End of the nice document.
2 changes: 2 additions & 0 deletions CsToMdTest/cstomd.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
//-

0 comments on commit ee60648

Please sign in to comment.