Last active
August 29, 2015 13:59
-
-
Save pohatu/10701938 to your computer and use it in GitHub Desktop.
ConvertTo-MarkDownTable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ConvertTo-MarkDownTable() | |
{ | |
$in = [windows.clipboard]::GetText() | |
$lines = $in.split("`n") | |
$out=@() | |
$out += $lines[0] -replace "`r",'' -replace "^","|" -replace ",","|" -replace "$","|`n" | |
$out += $lines[0] -replace "`r",'' -replace "\w+","---" -replace "^","|" -replace ",","|" -replace "$","|`n" | |
$out += $lines[1..($lines.Count-1)] -replace "`r", '' -replace "^", "|" -replace ",","|" -replace "$", "|`n" | |
[windows.clipboard]::SetText($out -join "") | |
} | |
## input is a comma-seperated multi-line segment | |
## ex: | |
## foo,bar,buzz,bazz,biff | |
## 1,2,3,4,5 | |
## 6,7,8,9,10 | |
## | |
## | |
## output is markdown-style table | |
## | |
## example: | |
## |foo|bar|buzz|bazz|biff| | |
## |---|---|---|---|---| | |
## |1|2|3|4|5| | |
## |6|7|8|9|10| | |
## doesn't care about right-aligned or centered, just does default. | |
## Doesn't care about pretty. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The following:
becomes:
which renders as: