-
Notifications
You must be signed in to change notification settings - Fork 29
/
Add-NotebookCell.ps1
43 lines (37 loc) · 1.13 KB
/
Add-NotebookCell.ps1
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
<#
.SYNOPSIS
When run within a Polyglot Notebook, appends a cell to it.
.PARAMETER Language
The cell language to use.
.FUNCTIONALITY
Notebooks
.INPUTS
Any object that can be converted to a string and used as cell content.
.EXAMPLE
"flowchart LR`nA --> B" |Add-NotebookCell.ps1 mermaid
Appends a cell with a Mermaid chart.
#>
#Requires -Version 7
using namespace Microsoft.DotNet.Interactive
using namespace Microsoft.DotNet.Interactive.Commands
[CmdletBinding()] Param(
# The cell content.
[Parameter(Mandatory=$true,ValueFromPipeline=$true)][psobject] $InputObject
)
DynamicParam
{
try {[Kernel]::Root.ChildKernels.Name |Add-DynamicParam.ps1 Language string}
catch {'csharp','fsharp','html','http','javascript','kql','mermaid','pwsh','sql','value','vscode' |Add-DynamicParam.ps1 Language string}
$DynamicParams
}
End
{
if(!$PSBoundParameters.ContainsKey('Language'))
{
[Kernel]::Root.SendAsync((New-Object SendEditableCode 'vscode',($input |Out-String))) |Out-Null
}
else
{
[Kernel]::Root.SendAsync((New-Object SendEditableCode $PSBoundParameters['Language'],($input |Out-String))) |Out-Null
}
}