Se hai scelto la via dello script, puoi aggiungere alla macro (o alla procedura manuale), l'esecuzione tramite menu Esegui (Run) in Notepad++ di:
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "percorso-script-PowerShell.ps1" "percorso-file-segnalibri.html"virgolette incluse, ma percorsi reali.
Prima devi salvare in un percorso a scelta, usando Notepad++, questo script con estensione .ps1:
param(
[Parameter(Mandatory = $true)]
[string]$InputFile
)
# Create the output filename next to the original.
$directory = [System.IO.Path]::GetDirectoryName($InputFile)
$baseName = [System.IO.Path]::GetFileNameWithoutExtension($InputFile)
$extension = [System.IO.Path]::GetExtension($InputFile)
$OutputFile = Join-Path $directory ($baseName + "-indented" + $extension)
# Read all lines while preserving the file's text content.
$lines = [System.IO.File]::ReadAllLines($InputFile)
$depth = 0
$result = [System.Collections.Generic.List[string]]::new()
foreach ($line in $lines) {
# Remove existing indentation.
$text = $line.TrimStart()
# Preserve completely blank lines.
if ($text -eq "") {
$result.Add("")
continue
}
# A closing DL ends the current nesting level,
# so decrease the depth BEFORE indenting this line.
if ($text -match '^\s*</DL\b') {
if ($depth -gt 0) {
$depth--
}
}
# Four spaces per nesting level, matching the usual
# formatting seen in Firefox bookmark HTML.
$result.Add((" " * $depth) + $text)
# An opening DL starts a new nesting level,
# so increase the depth AFTER indenting this line.
if ($text -match '<DL\b') {
$depth++
}
}
# Write UTF-8 without adding a BOM.
$utf8NoBom = [System.Text.UTF8Encoding]::new($false)
[System.IO.File]::WriteAllLines($OutputFile, $result, $utf8NoBom)
Write-Host ""
Write-Host "Finished."
Write-Host "Input : $InputFile"
Write-Host "Output: $OutputFile"
Write-Host ""
Read-Host "Press Enter to close"Dopo che sarà eseguito lo script, rimarrà aperta una finestra PowerShell che segnalerà l'avvenuta creazione del file denominato "(nome-originale)-indented.html" nello stesso percorso del file di segnalibri; per chiudere tale finestra è sufficiente premere un tasto.
Procedura testata una volta con successo.