Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConvertTo-HTML table to output #17

Open
VLoub opened this issue Mar 28, 2019 · 4 comments
Open

ConvertTo-HTML table to output #17

VLoub opened this issue Mar 28, 2019 · 4 comments
Labels
enhancement New feature or request

Comments

@VLoub
Copy link

VLoub commented Mar 28, 2019

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.

@markdomansky markdomansky added the enhancement New feature or request label May 5, 2019
@markdomansky
Copy link
Owner

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.

@schwallers
Copy link

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.

@animentork
Copy link

animentork commented May 16, 2022

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;
}

@schwallers
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants