diff --git a/Examples/Example30.ps1 b/Examples/Example30.ps1 new file mode 100644 index 0000000..aa9e264 --- /dev/null +++ b/Examples/Example30.ps1 @@ -0,0 +1,17 @@ +Import-Module PScribo -Force; + +$example30 = Document -Name 'PScribo Example 30' { + <# + When sending PScribo output as a HTML email body, Outlook does not necessarily + display the page styling/look-and-feel correctly. This can be suppressed by + passing an -Options hashtable with the 'NoPageLayoutStyle' key to the + Export-Document function. + #> + GlobalOption -Margin 18 + Style -Name StoppedService -Color White -BackgroundColor Firebrick + + $services = Get-Service + $services | Where-Object { $_.Status -ne 'Running' } | Set-Style -Style 'StoppedService' + Table -InputObject $services -Columns Name,DisplayName,Status -Headers 'Name','Display Name','State' +} +$example30 | Export-Document -Format Html -Path ~\Desktop -Options @{ NoPageLayoutStyle = $true } diff --git a/Functions/Export-Document.ps1 b/Functions/Export-Document.ps1 index 3a41cd7..9408f61 100644 --- a/Functions/Export-Document.ps1 +++ b/Functions/Export-Document.ps1 @@ -31,7 +31,12 @@ #try { ## Dynamically generate the output format function name $outputFormat = 'Out{0}' -f $f; - & $outputFormat -Document $Document -Path $Path; # -ErrorAction Stop; + if ($PSBoundParameters.ContainsKey('Options')) { + & $outputFormat -Document $Document -Path $Path -Options $Options; # -ErrorAction Stop; + } + else { + & $outputFormat -Document $Document -Path $Path; # -ErrorAction Stop; + } #} #catch [System.Management.Automation.CommandNotFoundException] { # Write-Warning ('Output format "{0}" is unsupported.' -f $f); diff --git a/Plugins/OutHtml.Internal.ps1 b/Plugins/OutHtml.Internal.ps1 index ff243dd..dfe1187 100644 --- a/Plugins/OutHtml.Internal.ps1 +++ b/Plugins/OutHtml.Internal.ps1 @@ -197,19 +197,23 @@ [OutputType([System.String])] param ( ## PScribo document styles - [Parameter(Mandatory, ValueFromPipeline)] [System.Collections.Hashtable] $Styles, + [Parameter(Mandatory, ValueFromPipelineByPropertyName)] [System.Collections.Hashtable] $Styles, ## PScribo document tables styles - [Parameter(Mandatory, ValueFromPipeline)] [System.Collections.Hashtable] $TableStyles + [Parameter(Mandatory, ValueFromPipelineByPropertyName)] [System.Collections.Hashtable] $TableStyles, + ## Suppress page layout styling + [Parameter(ValueFromPipelineByPropertyName)] [System.Management.Automation.SwitchParameter] $NoPageLayoutStyle ) process { $stylesBuilder = New-Object -TypeName 'System.Text.StringBuilder'; [ref] $null = $stylesBuilder.AppendLine('' | Should Be $true; } + + It 'creates page layout style by default' { + $Document = Document -Name 'Test' -ScriptBlock { }; + $text = OutHtmlStyle -Styles $Document.Styles -TableStyles $Document.TableStyles; + + $text -match 'html {' | Should Be $true; + $text -match 'page {' | Should Be $true; + $text -match '@media print {' | Should Be $true; + } + + It "suppresses page layout style when 'Options.NoPageLayoutSyle' specified" { + $Document = Document -Name 'Test' -ScriptBlock { }; + $text = OutHtmlStyle -Styles $Document.Styles -TableStyles $Document.TableStyles -NoPageLayoutStyle; + + $text -match 'html {' | Should Be $false; + $text -match 'page {' | Should Be $false; + $text -match '@media print {' | Should Be $false; + } } Describe 'OutHtmlTable' { diff --git a/Plugins/OutHtml.ps1 b/Plugins/OutHtml.ps1 index 5f88294..2fd7ed7 100644 --- a/Plugins/OutHtml.ps1 +++ b/Plugins/OutHtml.ps1 @@ -22,11 +22,15 @@ function OutHtml { process { $stopwatch = [System.Diagnostics.Stopwatch]::StartNew(); WriteLog -Message ($localized.DocumentProcessingStarted -f $Document.Name); + $noPageLayoutStyle = $false; + if ($Options -and ($Options['NoPageLayoutStyle'])) { + $noPageLayoutStyle = $Options['NoPageLayoutStyle']; + } [System.Text.StringBuilder] $htmlBuilder = New-Object System.Text.StringBuilder; [ref] $null = $htmlBuilder.AppendLine(''); [ref] $null = $htmlBuilder.AppendLine(''); [ref] $null = $htmlBuilder.AppendLine('{0}' -f $Document.Name); - [ref] $null = $htmlBuilder.AppendLine('{0}' -f (OutHtmlStyle -Styles $Document.Styles -TableStyles $Document.TableStyles)); + [ref] $null = $htmlBuilder.AppendLine('{0}' -f (OutHtmlStyle -Styles $Document.Styles -TableStyles $Document.TableStyles -NoPageLayoutStyle:$noPageLayoutStyle)); $topMargin = ConvertMmToEm $Document.Options['MarginTop']; $leftMargin = (ConvertMmToEm $Document.Options['MarginLeft']); $bottomMargin = (ConvertMmToEm $Document.Options['MarginBottom']); diff --git a/en-US/about_Plugins.help.txt b/en-US/about_Plugins.help.txt index 6d506b2..9a34fac 100644 --- a/en-US/about_Plugins.help.txt +++ b/en-US/about_Plugins.help.txt @@ -21,5 +21,6 @@ # Plugin-specific options # In their own about file? + HTML: NoPageLayoutStyle [bool]: Suppresses the page layout/look-and-feel style # Writing a plugin