Skip to content

Commit 16a5f68

Browse files
BernieWhitevors
authored andcommitted
Fix to preserve line break after headers issue #319 (#321)
* Updates to preserve blank line after header #319 * Updates to preserve blank line after header for examples and parameters * Updates to preserve parameter, input, output and to remove trailing line breaks related links * Avoid adding 2 extra lines after parameter body
1 parent 4ca79b2 commit 16a5f68

27 files changed

+713
-172
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
## Not released
55

66
* Clean up trailing whitespace during markdown generation [#225](https://github.com/PowerShell/platyPS/issues/225)
7+
* Preserve line breaks after headers when Update-MarkdownHelp is used [#319](https://github.com/PowerShell/platyPS/issues/319)
78

89
## 0.8.3
910

src/Markdown.MAML/Markdown.MAML.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
<Compile Include="Model\Markdown\MarkdownNode.cs" />
6262
<Compile Include="Model\Markdown\MarkdownNodeType.cs" />
6363
<Compile Include="Model\Markdown\ParagraphNode.cs" />
64+
<Compile Include="Model\Markdown\SectionBody.cs" />
65+
<Compile Include="Model\Markdown\SectionFormatOption.cs" />
6466
<Compile Include="Model\Markdown\SourceExtent.cs" />
6567
<Compile Include="Model\Markdown\TextNode.cs" />
6668
<Compile Include="Model\Markdown\HyperlinkSpan.cs" />

src/Markdown.MAML/Model/MAML/MamlCommand.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ namespace Markdown.MAML.Model.MAML
66
public class MamlCommand
77
{
88
public SourceExtent Extent { get; set; }
9+
910
public string Name { get; set; }
10-
public string Synopsis { get; set; }
11-
public string Description { get; set; }
11+
12+
public SectionBody Synopsis { get; set; }
13+
14+
public SectionBody Description { get; set; }
1215

1316
public List<MamlInputOutput> Inputs
1417
{
@@ -25,7 +28,7 @@ public List<MamlParameter> Parameters
2528
get { return _parameters; }
2629
}
2730

28-
public string Notes { get; set; }
31+
public SectionBody Notes { get; set; }
2932

3033
public bool IsWorkflow { get; set; }
3134

src/Markdown.MAML/Model/MAML/MamlExample.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using Markdown.MAML.Model.Markdown;
2+
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Text;
@@ -12,5 +13,10 @@ public class MamlExample
1213
public string Code { get; set; }
1314
public string Remarks { get; set; }
1415
public string Introduction { get; set; }
16+
17+
/// <summary>
18+
/// Additional options that determine how the section will be formated when rendering markdown.
19+
/// </summary>
20+
public SectionFormatOption FormatOption { get; set; }
1521
}
1622
}

src/Markdown.MAML/Model/MAML/MamlInputOutput.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using Markdown.MAML.Model.Markdown;
2+
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Text;
@@ -14,6 +15,11 @@ public class MamlInputOutput : IEquatable<MamlInputOutput>
1415
public string TypeName { get; set; }
1516
public string Description { get; set; }
1617

18+
/// <summary>
19+
/// Additional options that determine how the section will be formated when rendering markdown.
20+
/// </summary>
21+
public SectionFormatOption FormatOption { get; set; }
22+
1723
bool IEquatable<MamlInputOutput>.Equals(MamlInputOutput other)
1824
{
1925
if (!StringComparer.OrdinalIgnoreCase.Equals(other.TypeName, this.TypeName))

src/Markdown.MAML/Model/MAML/MamlParameter.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ public class MamlParameter : ICloneable
99
{
1010
public SourceExtent Extent { get; set; }
1111

12+
/// <summary>
13+
/// Additional options that determine how the section will be formated when rendering markdown.
14+
/// </summary>
15+
public SectionFormatOption FormatOption { get; set; }
16+
1217
public string Type { get; set; }
1318

1419
public string FullType { get; set; }

src/Markdown.MAML/Model/Markdown/HeadingNode.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@ public override MarkdownNodeType NodeType
99

1010
public int HeadingLevel { get; private set; }
1111

12-
public HeadingNode(string headingText, int headingLevel, SourceExtent sourceExtent)
12+
/// <summary>
13+
/// Additional options that determine how the section will be formated when rendering markdown. This options will be passed on to MAML models when they are generated.
14+
/// </summary>
15+
public SectionFormatOption FormatOption { get; private set; }
16+
17+
public HeadingNode(string headingText, int headingLevel, SourceExtent sourceExtent, SectionFormatOption formatOption)
1318
: base(headingText, sourceExtent)
1419
{
1520
this.HeadingLevel = headingLevel;
21+
this.FormatOption = formatOption;
1622
}
1723
}
1824
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Markdown.MAML.Model.Markdown
8+
{
9+
/// <summary>
10+
/// A section of text with formatting options.
11+
/// </summary>
12+
public sealed class SectionBody
13+
{
14+
public SectionBody(string text, SectionFormatOption formatOption)
15+
{
16+
Text = text;
17+
FormatOption = formatOption;
18+
}
19+
20+
public SectionBody(string text)
21+
: this(text, SectionFormatOption.None)
22+
{ }
23+
24+
/// <summary>
25+
/// The text of the section body.
26+
/// </summary>
27+
public string Text { get; private set; }
28+
29+
/// <summary>
30+
/// Additional options that determine how the section will be formated when rendering markdown.
31+
/// </summary>
32+
public SectionFormatOption FormatOption { get; private set; }
33+
34+
public override string ToString()
35+
{
36+
return Text;
37+
}
38+
}
39+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Markdown.MAML.Model.Markdown
8+
{
9+
/// <summary>
10+
/// Define options that determine how sections will be formated when rendering markdown.
11+
/// </summary>
12+
[Flags()]
13+
public enum SectionFormatOption : byte
14+
{
15+
None = 0,
16+
17+
/// <summary>
18+
/// A line break should be added after the section header.
19+
/// </summary>
20+
LineBreakAfterHeader = 1
21+
}
22+
}

src/Markdown.MAML/Parser/MarkdownParser.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,10 @@ private void CreateHashHeader(Match regexMatch, SourceExtent sourceExtent)
307307
new HeadingNode(
308308
regexMatch.Groups[2].Value,
309309
regexMatch.Groups[1].Value.Length,
310-
sourceExtent));
310+
sourceExtent,
311+
312+
// Detect if a line break after the header exists. Mutiple line breaks will be reduced to one.
313+
(regexMatch.Groups[3].Captures.Count > 1) ? SectionFormatOption.LineBreakAfterHeader : SectionFormatOption.None));
311314
}
312315

313316
private void CreateHashHeader2(Match regexMatch, SourceExtent sourceExtent)
@@ -318,7 +321,10 @@ private void CreateHashHeader2(Match regexMatch, SourceExtent sourceExtent)
318321
new HeadingNode(
319322
regexMatch.Groups[3].Value,
320323
regexMatch.Groups[2].Value.Length,
321-
sourceExtent));
324+
sourceExtent,
325+
326+
// Detect if a line break after the header exists. Mutiple line breaks will be reduced to one.
327+
(regexMatch.Groups[4].Captures.Count > 1) ? SectionFormatOption.LineBreakAfterHeader : SectionFormatOption.None));
322328
}
323329

324330
private void CreateUnderlineHeader(Match regexMatch, SourceExtent sourceExtent)
@@ -333,7 +339,10 @@ private void CreateUnderlineHeader(Match regexMatch, SourceExtent sourceExtent)
333339
new HeadingNode(
334340
regexMatch.Groups[1].Value,
335341
headerLevel,
336-
sourceExtent));
342+
sourceExtent,
343+
344+
// Detect if a line break after the header exists. Mutiple line breaks will be reduced to one.
345+
(regexMatch.Groups[3].Captures.Count > 1) ? SectionFormatOption.LineBreakAfterHeader : SectionFormatOption.None));
337346
}
338347

339348
private void CreateTickCodeBlock(Match regexMatch, SourceExtent sourceExtent)

0 commit comments

Comments
 (0)