« random links 2006-07-09 | Main | stevey's right, marketing matters »

rendering html from monad

I've just started dabbling with monad (aka "Windows Powershell"), so I tried porting my code for 'rendering HTML from irb' to it. It turns out to be a pretty good task for getting to know a new REPL environment.

Just for the record, this is what I came up with:

function Show-HTML ([string]$html) {
    $ie=New-Object -ComObject InternetExplorer.Application
    $ie.menubar=0
    $ie.toolbar=0
    $ie.statusbar=0
    $ie.navigate("about:blank")
    $ie.document.write($html)
    $html=[string]$input
    $ie.document.write($html)
    $ie.visible="true"
}

You can either pass a string param, as in Show-Html "Hello World!", or you can pipe HTML in. Monad also has a nifty builtin called 'ConvertTo-HTML' which pretty much does what it says. So in order to get the same HTML table of environment variables from the irb example, you could use

dir Env:  | ConvertTo-HTML Name,Value | Show-HTML

 

Comments

PSMDTAG:FAQ: How can I show HTML?

PSMDTAG:TYPE:COM: InternetExplorer.Application

Jeffrey Snover [MSFT]
Windows PowerShell/Aspen Architect
Visit the Windows PowerShell Team blog at: http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at: http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)