Created
July 13, 2020 03:07
-
-
Save vexx32/99da8f7eae73273c0ffdd106af0240a5 to your computer and use it in GitHub Desktop.
PowerShell script to retrieve lists of classes and ids from a html string and output a CSS skeleton for them
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
[System.Text.RegularExpressions.MatchCollection]$classesAndIds = [regex]::Matches($html, 'class="(?<Classes>[^"]+)"|id="(?<Id>[^"]+)"') | |
$classes = [System.Collections.Generic.HashSet[string]]::new() | |
$ids = [System.Collections.Generic.HashSet[string]]::new() | |
$classesAndIds.Captures.Groups.ForEach{ | |
if ($_.Name -eq 'Classes') { | |
$_.Value -split '[\s\r\n]' -replace '\{/?block:[^}]\}' | | |
Where-Object {$_} | | |
ForEach-Object { | |
$classes.Add(".$_ {`n`n}`n`n") > $null | |
} | |
} | |
elseif ($_.Name -eq 'Id') { | |
$ids.Add("#$($_.Value) {`n`n}`n`n") | |
} | |
} | |
@( | |
$ids | |
$classes | |
) -join "`n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment