Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/System.Management.Automation/help/HelpCommentsParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ private static void GetExampleSections(string content, out string prompt_str, ou
{
prompt_str = code_str = string.Empty;
StringBuilder builder = new StringBuilder();
string default_prompt_str = "PS > ";

int collectingPart = 1;
foreach (char c in content)
Expand All @@ -495,7 +496,7 @@ private static void GetExampleSections(string content, out string prompt_str, ou
{
if (collectingPart == 1)
{
prompt_str = "PS C:\\>";
prompt_str = default_prompt_str;
}
code_str = builder.ToString().Trim();
builder = new StringBuilder();
Expand All @@ -507,7 +508,7 @@ private static void GetExampleSections(string content, out string prompt_str, ou

if (collectingPart == 1)
{
prompt_str = "PS C:\\>";
prompt_str = default_prompt_str;
code_str = builder.ToString().Trim();
remarks_str = string.Empty;
}
Expand Down
15 changes: 11 additions & 4 deletions src/System.Management.Automation/help/MamlNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -606,13 +606,14 @@ private PSObject[] GetMamlFormattingPSObjects(XmlNode xmlNode)

int paraNodes = GetParaMamlNodeCount(xmlNode.ChildNodes);
int count = 0;

// Don't trim the content if this is an "introduction" node.
bool trim = ! string.Equals(xmlNode.Name, "maml:introduction", StringComparison.OrdinalIgnoreCase);
foreach (XmlNode childNode in xmlNode.ChildNodes)
{
if (childNode.LocalName.Equals("para", StringComparison.OrdinalIgnoreCase))
{
++count;
PSObject paraPSObject = GetParaPSObject(childNode, count != paraNodes);
PSObject paraPSObject = GetParaPSObject(childNode, count != paraNodes, trim: trim);
if (paraPSObject != null)
mshObjects.Add(paraPSObject);
continue;
Expand Down Expand Up @@ -752,8 +753,9 @@ private static string GetNodeIndex(XmlNode xmlNode)
/// </summary>
/// <param name="xmlNode"></param>
/// <param name="newLine"></param>
/// <param name="trim"></param>
/// <returns></returns>
private static PSObject GetParaPSObject(XmlNode xmlNode, bool newLine)
private static PSObject GetParaPSObject(XmlNode xmlNode, bool newLine, bool trim = true)
{
if (xmlNode == null)
return null;
Expand All @@ -771,7 +773,12 @@ private static PSObject GetParaPSObject(XmlNode xmlNode, bool newLine)
}
else
{
sb.Append(xmlNode.InnerText.Trim());
var innerText = xmlNode.InnerText;
if (trim)
{
innerText = innerText.Trim();
}
sb.Append(innerText);
}

mshObject.Properties.Add(new PSNoteProperty("Text", sb.ToString()));
Expand Down
14 changes: 14 additions & 0 deletions test/powershell/Language/Scripting/ScriptHelp.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -557,4 +557,18 @@ Describe 'get-help other tests' -Tags "CI" {
It '$x.Parameters.parameter[1].defaultValue' { $x.Parameters.parameter[1].defaultValue | Should -BeExactly '42' }
It '$x.Parameters.parameter[2].defaultValue' { $x.Parameters.parameter[2].defaultValue | Should -BeExactly 'parameter is mandatory' }
}

Context 'get-help -Examples prompt string should have trailing space' {
function foo {
<#
.EXAMPLE
foo bar
#>
param()
}

It 'prompt should be exactly "PS > " with trailing space' {
(Get-Help foo -Examples).examples.example.introduction.Text | Should -BeExactly "PS > "
}
}
}