generisches Skript für die Konvertierung von Markdown zu DOCX
This commit is contained in:
@@ -0,0 +1,74 @@
|
|||||||
|
param(
|
||||||
|
[Parameter(Mandatory = $false, Position = 0)]
|
||||||
|
[string]$RelativePath = ".",
|
||||||
|
|
||||||
|
[Parameter(Mandatory = $false)]
|
||||||
|
[switch]$Recurse
|
||||||
|
)
|
||||||
|
|
||||||
|
$scriptDir = $PSScriptRoot
|
||||||
|
|
||||||
|
$refDoc = Join-Path $scriptDir 'referenz.docx'
|
||||||
|
$luaFilter = Join-Path $scriptDir 'filter.lua'
|
||||||
|
|
||||||
|
$targetDir = Join-Path $scriptDir $RelativePath
|
||||||
|
|
||||||
|
if (-not (Test-Path $targetDir)) {
|
||||||
|
Write-Error "Der Zielordner '$targetDir' existiert nicht."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
$mdFiles = Get-ChildItem -Path $targetDir -Filter '*.md' -Recurse:$Recurse
|
||||||
|
|
||||||
|
if ($mdFiles.Count -eq 0) {
|
||||||
|
Write-Host "Keine .md-Dateien in '$targetDir' gefunden." -ForegroundColor Yellow
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Verarbeite Ordner: $targetDir (Rekursiv: $Recurse)" -ForegroundColor Yellow
|
||||||
|
|
||||||
|
# --- 1. DATEIEN AUFLISTEN ---
|
||||||
|
Write-Host "`nFolgende $($mdFiles.Count) Datei(en) werden verarbeitet:" -ForegroundColor Yellow
|
||||||
|
foreach ($file in $mdFiles) {
|
||||||
|
# Zeigt den relativen Pfad ab dem Zielordner für bessere Lesbarkeit
|
||||||
|
$relativePath = Resolve-Path -Path $file.FullName -RelativeBasePath $targetDir
|
||||||
|
Write-Host " - $relativePath" -ForegroundColor Gray
|
||||||
|
}
|
||||||
|
Write-Host ""
|
||||||
|
|
||||||
|
# --- 2. NUTZERABFRAGE ---
|
||||||
|
$response = Read-Host "Möchtest du diese Dateien konvertieren? Bereits vorhandene .docx-Dateien werden überschrieben (J/N)"
|
||||||
|
|
||||||
|
# Prüft, ob der Nutzer mit 'j' oder 'ja' geantwortet hat (case-insensitive)
|
||||||
|
if ($response -notmatch '^[jJ](a)?$') {
|
||||||
|
Write-Host "Vorgang vom Benutzer abgebrochen." -ForegroundColor Red
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "`nStarte Konvertierung..." -ForegroundColor Green
|
||||||
|
|
||||||
|
$pandocArgs = @()
|
||||||
|
|
||||||
|
if (Test-Path $refDoc) {
|
||||||
|
$pandocArgs += "--reference-doc=$refDoc"
|
||||||
|
} else {
|
||||||
|
Write-Host "Hinweis: 'referenz.docx' wurde im Skriptordner nicht gefunden und wird übersprungen." -ForegroundColor DarkGray
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Test-Path $luaFilter) {
|
||||||
|
$pandocArgs += "--lua-filter=$luaFilter"
|
||||||
|
} else {
|
||||||
|
Write-Host "Hinweis: 'nohr.lua' wurde im Skriptordner nicht gefunden und wird übersprungen." -ForegroundColor DarkGray
|
||||||
|
}
|
||||||
|
|
||||||
|
# --- 3. KONVERTIERUNGSDURCHLAUF ---
|
||||||
|
foreach ($file in $mdFiles) {
|
||||||
|
Write-Host "Konvertiere $($file.Name) ($($file.DirectoryName))..." -ForegroundColor Cyan
|
||||||
|
|
||||||
|
$destDocx = Join-Path $file.DirectoryName "$($file.BaseName).docx"
|
||||||
|
|
||||||
|
# Pandoc-Befehl ausführen (Splatting über das Array $pandocArgs)
|
||||||
|
pandoc $file.FullName -o $destDocx @pandocArgs
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Fertig! Alle Markdown-Dateien wurden konvertiert." -ForegroundColor Green
|
||||||
Reference in New Issue
Block a user