Skip to content

Instantly share code, notes, and snippets.

@vexx32
Created July 13, 2020 03:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vexx32/99da8f7eae73273c0ffdd106af0240a5 to your computer and use it in GitHub Desktop.
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
[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