diff --git a/src/System.Management.Automation/help/HelpCommentsParser.cs b/src/System.Management.Automation/help/HelpCommentsParser.cs
index 196233aeec7..833a8cb2097 100644
--- a/src/System.Management.Automation/help/HelpCommentsParser.cs
+++ b/src/System.Management.Automation/help/HelpCommentsParser.cs
@@ -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)
@@ -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();
@@ -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;
}
diff --git a/src/System.Management.Automation/help/MamlNode.cs b/src/System.Management.Automation/help/MamlNode.cs
index 539be02b797..6fac1566795 100644
--- a/src/System.Management.Automation/help/MamlNode.cs
+++ b/src/System.Management.Automation/help/MamlNode.cs
@@ -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;
@@ -752,8 +753,9 @@ private static string GetNodeIndex(XmlNode xmlNode)
///
///
///
+ ///
///
- private static PSObject GetParaPSObject(XmlNode xmlNode, bool newLine)
+ private static PSObject GetParaPSObject(XmlNode xmlNode, bool newLine, bool trim = true)
{
if (xmlNode == null)
return null;
@@ -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()));
diff --git a/test/powershell/Language/Scripting/ScriptHelp.Tests.ps1 b/test/powershell/Language/Scripting/ScriptHelp.Tests.ps1
index bf854960fb8..5536ea745f2 100644
--- a/test/powershell/Language/Scripting/ScriptHelp.Tests.ps1
+++ b/test/powershell/Language/Scripting/ScriptHelp.Tests.ps1
@@ -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 > "
+ }
+ }
}