Skip to content

Instantly share code, notes, and snippets.

@wgross
Created July 20, 2017 18:30
Show Gist options
  • Save wgross/0fba55944d05747d2b1bf01d4d25ebd5 to your computer and use it in GitHub Desktop.
Save wgross/0fba55944d05747d2b1bf01d4d25ebd5 to your computer and use it in GitHub Desktop.
powershell html generator syntax experiment
using namespace System.Xml.Linq
@(
"html"
"head"
"body"
)|Foreach-Object -Process {
@"
function global:$_ {
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline)]
`$ContentPipe,
[Parameter(Position=0)]
[scriptblock]`$ContentBlock
)
begin {
"<$_>"|Write-Output
}
process {
if(`$ContentBlock) {
`$ContentBlock.InvokeReturnAsIs()|Write-Output
}
`$ContentPipe | Write-Output
}
end {
"</$_>"|Write-Output
}
}
"@|Invoke-Expression
}
$data = (html {
"blah"|head
"zumsel"|body
})
$data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment