-
Notifications
You must be signed in to change notification settings - Fork 16
Xml to markdown with Workflow #132
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
Changes from all commits
b41f473
a86b6a7
b840d3d
17ff571
8e709ad
346a657
3afe460
4fcf9af
dfb894e
08cd660
2a5c592
cc3109c
c2298ed
d92eaf3
c9b1029
e70fca2
78199e6
93901c0
01fb5d5
ca7854e
82bf5ad
2a3957e
805daa6
c7c6c4c
2d6ad13
59ea57a
b0ee0bc
d786a5b
747496e
5a6eed5
f62cbf7
fde717f
117388a
49bf2bd
d850aed
703ef59
f35ef84
0d12591
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#if the guidelines xml file is modified between commits to the master branch the associate markdown file is updated | ||
name: Update csharp Markdown | ||
|
||
on: | ||
push: | ||
branches: | ||
- 'master' | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
env: | ||
XmlFileName: "Guidelines(8th Edition).xml" | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
ref: ${{ github.ref }} | ||
- name: Simple Diff | ||
uses: mudlabs/simple-diff@v1.0.2 | ||
id: diff | ||
with: | ||
# The path of the file or folder to find in the commits diff tree. | ||
path: ./docs/${{ env.XmlFileName }} | ||
# continue even if the xml file if the file isn't found in the diff tree (it wasn't changed). strict=true causes the action to fail otherwise | ||
strict : false | ||
- name: Guidelines xml status | ||
run: | | ||
echo "${{ env.XmlFileName }} modified = ${{ steps.diff.outputs.modified }}" | ||
echo "${{ steps.diff.outputs.name }}" | ||
|
||
- name: Setup .NET Core | ||
uses: actions/setup-dotnet@v1 | ||
with: | ||
dotnet-version: 3.1.301 | ||
if: steps.diff.outputs.modified == true | ||
|
||
- name: restore_compile_run_createMD | ||
run: | | ||
dotnet restore | ||
dotnet run --configuration Release --project ./XMLtoMD/GuidelineXmlToMD/GuidelineXmlToMD.csproj | ||
./XMLtoMD/GuidelineXmlToMD/bin/Release/netcoreapp3.1/GuidelineXmlToMD "${{ env.XmlFileName }}" | ||
if: steps.diff.outputs.modified == true | ||
|
||
- name: Create commit and push to CodingGuideLinesMDUpdate | ||
run: | | ||
git config user.name '${{ github.actor }}' | ||
git config user.email '${{ github.actor }}@users.noreply.github.com' | ||
git add -A | ||
git commit -m "new coding guidelines MD File created" | ||
git push origin '${{ github.ref }}' | ||
if: steps.diff.outputs.modified == true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// This file is used by Code Analysis to maintain SuppressMessage | ||
// attributes that are applied to this project. | ||
// Project-level suppressions either have no target or are given | ||
// a specific target and scoped to a namespace, type, member, etc. | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
|
||
[assembly: SuppressMessage("Globalization", "CA1307:Specify StringComparison", Justification = "<Pending>")] | ||
[assembly: SuppressMessage("Globalization", "CA1303:Do not pass literals as localized parameters", Justification = "From an Old Github Project, not for production")] | ||
[assembly: SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "<Pending>")] | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,32 @@ | ||||||
using System.Collections.Generic; | ||||||
|
||||||
|
||||||
namespace GuidelineXmlToMD | ||||||
{ | ||||||
public class Guideline | ||||||
{ | ||||||
public string Key { get; set; } = ""; | ||||||
public string Text { get; set; } = ""; | ||||||
|
||||||
public string Severity { get; set; } = ""; | ||||||
|
||||||
public string Section { get; set; } = ""; | ||||||
public string Subsection { get; set; } = ""; | ||||||
|
||||||
public List<string> Comments { get;} = new List<string>(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Suggested change
|
||||||
|
||||||
public override int GetHashCode() | ||||||
{ | ||||||
return Key.GetHashCode(); | ||||||
} | ||||||
|
||||||
public override bool Equals(object obj) | ||||||
{ | ||||||
Guideline otherGuideline = obj as Guideline; | ||||||
|
||||||
return otherGuideline != null && string.Equals(otherGuideline.Key, this.Key); | ||||||
} | ||||||
|
||||||
} | ||||||
|
||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Xml.Linq; | ||
|
||
namespace GuidelineXmlToMD | ||
{ | ||
static class GuidelineXmlFileReader | ||
{ | ||
public const string _Guideline = "guideline"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be nice if these constants were put in their own static class. Since these are related to the structure of the XML and should be put in a class with a name that reflects that. An even cleaner option is to use |
||
public const string _Key = "key"; | ||
public const string _Severity = "severity"; | ||
|
||
public const string _Section = "section"; | ||
public const string _Subsection = "subsection"; | ||
public const string _Comments = "comments"; | ||
|
||
|
||
public static ICollection<Guideline> ReadExisitingGuidelinesFile(string pathToExistingGuidelinesXml) | ||
{ | ||
|
||
XDocument previousGuidelines = XDocument.Load(pathToExistingGuidelinesXml); | ||
|
||
HashSet<Guideline> guidelines = new HashSet<Guideline>(); | ||
|
||
foreach (XElement guidelineFromXml in previousGuidelines.Root.DescendantNodes().OfType<XElement>()) | ||
{ | ||
Guideline guideline = new Guideline(); | ||
guideline.Severity = guidelineFromXml.Attribute(_Severity)?.Value; | ||
guideline.Subsection = guidelineFromXml.Attribute(_Subsection)?.Value; | ||
guideline.Section = guidelineFromXml.Attribute(_Section)?.Value; | ||
guideline.Text = guidelineFromXml?.Value; | ||
guideline.Key = guidelineFromXml.Attribute(_Key)?.Value; | ||
|
||
guidelines.Add(guideline); | ||
} | ||
return guidelines; | ||
} | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="MarkdownOut\" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="IntelliTect.Analyzers" Version="0.1.8" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
| ||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.30225.117 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GuidelineXmlToMD", "GuidelineXmlToMD.csproj", "{D9C7CC15-01DB-46FE-922A-6EB41CE1759B}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{D9C7CC15-01DB-46FE-922A-6EB41CE1759B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{D9C7CC15-01DB-46FE-922A-6EB41CE1759B}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{D9C7CC15-01DB-46FE-922A-6EB41CE1759B}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{D9C7CC15-01DB-46FE-922A-6EB41CE1759B}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {A1FCF330-0100-466C-A566-FF92F0B59E10} | ||
EndGlobalSection | ||
EndGlobal |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,47 @@ | ||||||
namespace MarkdownOut { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Braces should be put on their own line. The .editorconfig should be flagging these. If it isn't it could be because it is a level higher than the solution. If that is the case, don't have a separate solution for this project and just added to the main solution. |
||||||
|
||||||
/// <summary> | ||||||
/// A container for extension methods related to Markdown styling and formatting. | ||||||
/// </summary> | ||||||
public static class MdExtensions { | ||||||
|
||||||
/// <summary> | ||||||
/// Styles one or more substrings of the provided string using the specified | ||||||
/// <see cref="MdStyle"/>. | ||||||
/// </summary> | ||||||
/// <param name="str">The string containing the substring to style.</param> | ||||||
/// <param name="substring">The substring to style.</param> | ||||||
/// <param name="style">The Markdown style to apply.</param> | ||||||
/// <param name="firstOnly"> | ||||||
/// If true, only the first occurrence of the substring is styled; otherwise, all | ||||||
/// occurrences of the substring are styled. | ||||||
/// </param> | ||||||
/// <returns> | ||||||
/// The selectively styled string. If <paramref name="str"/> does not contain any | ||||||
/// occurrences of <paramref name="substring"/>, it is returned unchanged. | ||||||
/// </returns> | ||||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Globalization", "CA1303:Do not pass literals as localized parameters", Justification = "<Pending>")] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This appears to duplicate the one in the global suppression file. |
||||||
public static string StyleSubstring(this string str, string substring, MdStyle style, | ||||||
bool firstOnly = false) { | ||||||
if (string.IsNullOrEmpty(str)) | ||||||
{ | ||||||
throw new System.ArgumentException("cannot stylize empty string", nameof(str)); | ||||||
} | ||||||
|
||||||
if (string.IsNullOrEmpty(substring)) | ||||||
{ | ||||||
throw new System.ArgumentException("cannot stylize empty string", nameof(str)); | ||||||
} | ||||||
|
||||||
if (!firstOnly) { | ||||||
return str?.Replace(substring, MdText.Style(substring, style), System.StringComparison.Ordinal); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
int pos = str.IndexOf(substring, System.StringComparison.Ordinal); | ||||||
if (pos < 0) { | ||||||
return str; | ||||||
} | ||||||
return str.Substring(0, pos) + MdText.Style(substring, style) | ||||||
+ str.Substring(pos + substring.Length); | ||||||
} | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
namespace MarkdownOut { | ||
|
||
/// <summary> | ||
/// Specifies a Markdown format to apply to a line or block of text. Formats are applied with a | ||
/// prefix string and, unlike Markdown styles (see <see cref="MdStyle"/>), cannot be selectively | ||
/// applied to substrings. | ||
/// </summary> | ||
public enum MdFormat { | ||
|
||
/// <summary> | ||
/// No text format. | ||
/// </summary> | ||
None, | ||
|
||
/// <summary> | ||
/// Heading 1 text format (inserts the string <c>"# "</c> in front of text). | ||
/// </summary> | ||
Heading1, | ||
|
||
/// <summary> | ||
/// Heading 2 text format (inserts the string <c>"## "</c> in front of text). | ||
/// </summary> | ||
Heading2, | ||
|
||
/// <summary> | ||
/// Heading 3 text format (inserts the string <c>"### "</c> in front of text). | ||
/// </summary> | ||
Heading3, | ||
|
||
/// <summary> | ||
/// Heading 4 text format (inserts the string <c>"#### "</c> in front of text). | ||
/// </summary> | ||
Heading4, | ||
|
||
/// <summary> | ||
/// Heading 5 text format (inserts the string <c>"##### "</c> in front of text). | ||
/// </summary> | ||
Heading5, | ||
|
||
/// <summary> | ||
/// Heading 6 text format (inserts the string <c>"###### "</c> in front of text). | ||
/// </summary> | ||
Heading6, | ||
|
||
/// <summary> | ||
/// Quote text format (inserts the string <c>"> "</c> in front of text). | ||
/// </summary> | ||
Quote, | ||
|
||
/// <summary> | ||
/// Unordered list item text format (inserts the string <c>"- "</c> in front of text). | ||
/// </summary> | ||
UnorderedListItem, | ||
|
||
/// <summary> | ||
/// Ordered list item text format (inserts the string <c>"1. "</c> in front of text). | ||
/// </summary> | ||
OrderedListItem, | ||
|
||
/// <summary> | ||
/// Creates a link to the heading that matches text to write (formats the text as [Foo](#foo)). | ||
/// </summary> | ||
InternalLink, | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
namespace MarkdownOut { | ||
|
||
/// <summary> | ||
/// Specifies a Markdown style to apply to a string of text. Styles are applied by wrapping text | ||
/// with a special string on each side and can be selectively applied to substrings. | ||
/// </summary> | ||
public enum MdStyle { | ||
|
||
/// <summary> | ||
/// No text styling. | ||
/// </summary> | ||
None, | ||
|
||
/// <summary> | ||
/// Italic text styling (surrounds text with a single <c>*</c> character on each side). | ||
/// </summary> | ||
Italic, | ||
|
||
/// <summary> | ||
/// Bold text styling (surrounds text with two <c>*</c> characters on each side). | ||
/// </summary> | ||
Bold, | ||
|
||
/// <summary> | ||
/// Bold italic text styling (surrounds text with three <c>*</c> characters on each side). | ||
/// </summary> | ||
BoldItalic, | ||
|
||
/// <summary> | ||
/// Code text styling (surrounds text with a single <c>`</c> character on each side). | ||
/// </summary> | ||
Code, | ||
|
||
/// <summary> | ||
/// Strike-through text styling (surrounds text with two <c>~</c> characters on each side). | ||
/// This style may not be supported by all Markdown parsers. | ||
/// </summary> | ||
StrikeThrough, | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suppressed warnings should have Justification filled out or be addressed.