Skip to content

Commit 8a82a4b

Browse files
Add line breaks in MAML for examples content (#770)
1 parent 8e23dec commit 8a82a4b

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

src/Command/ExportMamlCommandHelp.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,15 @@ protected override void EndProcessing()
9696
}
9797
else
9898
{
99-
WriteObject(this.InvokeProvider.Item.Get(MamlConversionHelper.WriteToFile(helpInfos, moduleMamlPath, Encoding).FullName));
99+
var mamlFile = MamlConversionHelper.WriteToFile(helpInfos, moduleMamlPath, Encoding);
100+
101+
// Read the MAML file and replace the specific line
102+
string mamlContent = File.ReadAllText(mamlFile.FullName, Encoding);
103+
// Replace the line break placeholder with a proper line break
104+
// This is a workaround for the issue where line breaks are not preserved in MAML files
105+
string updatedContent = mamlContent.Replace("<maml:para>__REMOVE_ME_LINE_BREAK__</maml:para>", "<maml:para>&#x20;&#x08;</maml:para>");
106+
File.WriteAllText(mamlFile.FullName, updatedContent, Encoding);
107+
WriteObject(this.InvokeProvider.Item.Get(mamlFile.FullName));
100108
}
101109
}
102110
}

src/MamlWriter/MamlHelpers.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,25 @@ private static Parameter ConvertParameter(Model.Parameter parameter)
194194

195195
private static CommandExample ConvertExample(Example example, int exampleNumber)
196196
{
197+
var tempDescription = new List<string>();
197198
var newExample = new CommandExample();
198199
newExample.Title = string.Format($"--------- {example.Title} ---------");
199200
foreach(string s in example.Remarks.Split(new string[] { "\n\n" }, StringSplitOptions.None))
200201
{
201-
newExample.Description.Add(s.Trim());
202+
tempDescription.Add(s.Trim());
202203
}
204+
205+
for (int i = 0; i < tempDescription.Count; i++)
206+
{
207+
newExample.Description.Add(tempDescription[i]);
208+
209+
// Add an empty line after each item except the last
210+
if (i < tempDescription.Count - 1)
211+
{
212+
newExample.Description.Add("__REMOVE_ME_LINE_BREAK__"); // Non-breaking space for empty line
213+
}
214+
}
215+
203216
return newExample;
204217
}
205218

test/Pester/ExportMamlCommandHelp.Tests.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,5 +129,11 @@ Describe "Export-MamlCommandHelp tests" {
129129
$observed = $xml2.SelectNodes('//command:command', $ns2).Where({$_.details.name -eq "Get-Date"}).examples.example.title
130130
$observed | Should -Be $expected
131131
}
132+
133+
It "Should have the line break workaround in the example code" {
134+
$m = Import-MarkdownCommandHelp -Path (Join-Path $assetDir 'get-date.md')
135+
$mamlFie = $m | Export-MamlCommandHelp -OutputFolder $outputDirectory -Force
136+
$mamlFie | Should -FileContentMatch '<maml:para>&#x20;&#x08;</maml:para>'
137+
}
132138
}
133139
}

0 commit comments

Comments
 (0)