iainbrighton / PScribo

PowerShell documentation framework
MIT License
231 stars 35 forks source link

HTML / Table Cell: Conten with Newlines: Linebreaks are removed #46

Closed schittli closed 7 years ago

schittli commented 7 years ago

Good evening Thank you very much for this really wonderful PowerShell-Module!, it's really great to see how you embedded the Document formatting into the PowerShell Syntax.

I have a small problem and was not able to find a solution: I would like to print a table with a Title and a Description which is a string which contains newlines, e.g.:

Title:       xxxx
Description: Line 1
             Line 2

PScribo renders ith this way:

Title:       xxxx
Description: Line 1 Line 2

I tried to split the Description into a string[], but the Parser is not able to handle it:

$GPOInfo | % {
    Section "GPOs $($_.DisplayName)" -Style Heading2 -ScriptBlock {
        $GPODetail = [Ordered] @{
            Name = $_.DisplayName
            Description = ($_.Description -split [environment]::NewLine)
        }
        New-Object -TypeName PSObject -Property $GPODetail | Table -List
    }
}

Does someone knows a solution how to replace Newlines by Linebreaks?

Thanks a lot for any help in advance, kind regards, Tom

iainbrighton commented 7 years ago

@schittli If you're only interested in HTML output then you should be able to do this:

Import-Module -Name PScribo
$GPOInfo = [PSCustomObject] @{
    DisplayName = 'Example GPO';
    Description = "This description`r`nincludes a line break";
}

Document HtmlTableLinkBreaks {
    $GPOInfo | % {
        Section "GPOs $($_.DisplayName)" -Style Heading2 -ScriptBlock {
            $GPODetail = [Ordered] @{
                Name = $_.DisplayName
                            ## Replace all line breaks with a HTML line break
                Description = ($_.Description -replace "`r`n","<br />")
            }
            New-Object -TypeName PSObject -Property $GPODetail | Table -List
        }
    }
} 

Obviously, if you were to try this with Text or Word output, then it wouldn't work 😞.

schittli commented 7 years ago

Hi @iainbrighton

Thank you very much for your fast answer and the complete example!, we really just use HTML output and therefore, your code works great.

And it's good to know that we can use HTML-Tags like <br />. We will avoid it, but sometimes they can be lifesavers :-)

Thanks a lot, kind regards, Tom