WebJEA icon indicating copy to clipboard operation
WebJEA copied to clipboard

ConvertTo-HTML table to output

Open VLoub opened this issue 6 years ago • 4 comments
trafficstars

Hi,

Is it possible to do ConvertTo-HTML -Fragment inside PS and pass it to web page? I would love to give users some tables, but i don't see simple way to do so.

And if there would be .pstable in PsOutput.css it would be a master piece.

VLoub avatar Mar 28 '19 17:03 VLoub

I'll add this as a feature to consider. I'll have to do some testing to see if it exposes any js injection vulnerabilities.

markdomansky avatar May 05 '19 14:05 markdomansky

Any way to do table formatting would be great. Currently when I try to color items in an object by wrapping an item in '[[span|psred|SOMETEXT]]' it messes up the format-table -AutoSize when the span is replaced on output.

schwallers avatar May 10 '22 03:05 schwallers

It is possible, albeit only using multiple [[span]] together with different CSS classes (which you can conveniently style in psoutput.css) to essentially fake the table.

Here is what I do (where $my_data further down holds the table-like data):

$columns = @("Column1", "Column2", "Column3")

$html = "[[span|table|"

$html = $html + "[[span|table-caption|My Table]]"

$html = $html + "[[span|table-header|"

# add header columns
foreach ($column in $columns) {
    $html = $html + "[[span|table-header-cell|" + $column + "]]"
}

# close header
$html = $html + "]]"

# add body
$html = $html + "[[span|table-body|"

# add rows
foreach ($row in $my_data) {
    $html = $html + "[[span|table-row|"

    # add cells
    foreach ($column in $columns) {
        $html = $html + "[[span|table-body-cell|" + $row.psobject.Properties[$column].Value + "]]"
    }

    # close row
    $html = $html + "]]"
}

# close body
$html = $html + "]]"

# close table
$html = $html + "]]"

# Output the formatted string:
$html

Now in the psoutput.css file you can style the classes, for example:

.table {
	width: 100%;
	display: table;
}

.table-caption{
	display: table-caption;
	text-align: center;
	font-size: 1.0rem;
	font-weight: bold;
}

.table-header{
	display: table-header-group;
	background-color: gray;
	font-weight: bold;
	font-size: 0.8rem;
}

.table-header-cell{
	display: table-cell;
	padding: 4px;
	text-align: justify;
	border-bottom: 2px solid black;
}

.table-body{
	display: table-row-group;
}

.table-row{
	display: table-row;
}

.table-body-cell{
	display: table-cell;
	padding: 4px;
	border-bottom: 1px solid black;
}

animentork avatar May 16 '22 09:05 animentork

That's really cool. I just tried it out and like it. The only problem is that it doesn't handle a link in a table-body-cell. [[span|table-body-cell|[[a|url|display]]]] Looks like it isn't putting the into the output correctly. Opening a separate defect.

schwallers avatar May 17 '22 03:05 schwallers