-
-
Notifications
You must be signed in to change notification settings - Fork 41
Closed
Description
I'm sorry if it's a dumb question, but I've been trying to format CSS (prettify) the same way I do for HTML and for some reason things fail for me. I know the code is in PowerShell (which is loading your NET library) but I don't have a way to build this in C#.
This is the output I'm getting. Is it like I'm missing small detail or a bug (unlikely)?
function Format-CSS {
[CmdletBinding()]
param(
[string] $File,
[string] $OutputFile
)
if ($File -and (Test-Path -LiteralPath $File)) {
$FileContent = [IO.File]::ReadAllText($file)
$CssParser = New-Object -TypeName AngleSharp.Css.Parser.CssParser
$ParsedDocument = $CssParser.ParseStyleSheet($FileContent)
$StringWriter = [System.IO.StringWriter]::new()
$PrettyMarkupFormatter = New-Object -TypeName AngleSharp.Css.PrettyStyleFormatter
$ParsedDocument.ToCss($StringWriter, $PrettyMarkupFormatter)
$FormattedCSS = $StringWriter.ToString()
if ($FormattedCSS) {
[IO.File]::WriteAllText($OutputFile, $FormattedCSS)
}
}
}
HTML is 99% the same, and it works just fine.
function Format-HTML {
[CmdletBinding()]
param(
[string] $File,
[string] $OutputFile
)
if ($File -and (Test-Path -LiteralPath $File)) {
$FileContent = [IO.File]::ReadAllText($file)
$HTMLParser = New-Object -TypeName AngleSharp.Html.Parser.HtmlParser
$ParsedDocument = $HTMLParser.ParseDocument($FileContent)
$StringWriter = [System.IO.StringWriter]::new()
$PrettyMarkupFormatter = New-Object -TypeName AngleSharp.Html.PrettyMarkupFormatter
$ParsedDocument.ToHtml($StringWriter, $PrettyMarkupFormatter)
#$ParsedDocument.StyleSheets
$FormattedHTML = $StringWriter.ToString()
if ($FormattedHTML) {
[IO.File]::WriteAllText($OutputFile, $FormattedHTML)
}
}
}
What am I missing? Would you be able to provide simple C# based example how you would format CSS natively?