forked from dfinke/PowerShellScottPlot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPSGraphNB.ps1
More file actions
61 lines (47 loc) · 1.76 KB
/
Copy pathPSGraphNB.ps1
File metadata and controls
61 lines (47 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using namespace "Microsoft.DotNet.Interactive"
function Write-Notebook {
# via James O'Neill, in https://github.com/dfinke/PowerShellPivot
<#
.SYNOPSIS
Writes to the output part of the current cell (a streamlined version of Out-Display)
.PARAMETER Html
Output to be sent as Hmtl
.PARAMETER Text
Output to be sent as plain text
.PARAMETER PassThru
If specified returns the output object, allowing it to be updated.
.EXAMPLE
> $statusMsg = Write-Notebook -PassThru -text "Step 1"
> ...
> $statusmsg.update("Step2")
Displays and updates text in the current cell output
.EXAMPLE
> $PSVersionTable | ConvertTo-Html -Fragment | Write-Notebook
Converts $psversionTable to a table and displays it. Without Write-Notebook the HTML markup would appear.
#>
[cmdletbinding(DefaultParameterSetName = 'Html')]
param (
[parameter(Mandatory = $true, ParameterSetName = 'Html', ValueFromPipeline = $true, Position = 1 )]
$Html,
[parameter(Mandatory = $true, ParameterSetName = 'Text')]
$Text,
[Alias('PT')]
[switch]$PassThru
)
begin { $htmlbody = @() }
process { if ($html) { $htmlbody += $Html } }
end {
if ($htmlbody.count -gt 0) { $result = [Kernel]::display([Kernel]::HTML($htmlbody), 'text/html') }
if ($Text) { $result = [Kernel]::display($Text, 'text/plain') }
if ($PassThru) { return $result }
}
}
function Show-ImageInNotebook {
param(
$DestinationPath
)
$png = [System.IO.File]::ReadAllBytes($DestinationPath)
$b64 = [System.Convert]::ToBase64String($png)
$img = '<img src="data:image/png; base64, {0}"></img>' -f $b64
Write-Notebook -Html $img
}