azurefieldnotes / ReportHTML

47 stars 21 forks source link

images and links using PSCustomObject as input #15

Open spaelling opened 5 years ago

spaelling commented 5 years ago

Added functions so that one can do links and images using below input.

This allows for more complex input than replacing URLx in a string.

It also makes it fairly easy to make an image link (param4)

Before calling ConvertTo-Html all input properties that are PSCustomObject are replaced with a guid. After the conversion the html is rendered and the guid is replaced.

$ArrayOfObjects = New-Object 'System.Collections.Generic.List[System.Object]'

$obj = [PSCustomObject]@{
    param1 = [PSCustomObject]@{
        _type = 'img'
        src = 'http://ihavecat.com/wp-content/uploads/2014/01/cat-asking-for-help-2.jpg'
        alt = 'cat asking for help'
        width = 60
        height = 60
    }
    param2 = [PSCustomObject]@{
        _type = 'link'
        url = 'https://www.w3schools.com'
        target = '_blank'
        Content = 'Visit w3schools!'
    }
    param3 = 'simpleparam'
    param4 = [PSCustomObject]@{
        _type = 'link'
        url = 'http://ihavecat.com/wp-content/uploads/2014/01/cat-asking-for-help-2.jpg'
        target = '_blank'
        Content = [PSCustomObject]@{
            _type = 'img'
            src = 'http://ihavecat.com/wp-content/uploads/2014/01/cat-asking-for-help-2.jpg'
            alt = 'cat asking for help'
            width = 60
            height = 60
        }
    }
}
$ArrayOfObjects.Add($obj)