2024-10-01 15:11:03 +02:00
|
|
|
|
<#
|
2023-04-11 22:28:51 +02:00
|
|
|
|
.SYNOPSIS
|
|
|
|
|
Converts .DOCX file(s) into Markdown
|
|
|
|
|
.DESCRIPTION
|
|
|
|
|
This PowerShell script converts .DOCX file(s) into Markdown.
|
|
|
|
|
.PARAMETER FilePattern
|
|
|
|
|
Specifies the file pattern to the .DOCX file(s)
|
|
|
|
|
.EXAMPLE
|
|
|
|
|
PS> ./convert-docx2md *.docx
|
|
|
|
|
.LINK
|
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
|
.NOTES
|
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
|
|
|
|
#>
|
|
|
|
|
|
|
|
|
|
param([string]$FilePattern = "")
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
|
|
|
|
|
|
|
|
|
if ($FilePattern -eq "" ) { $FilePattern = Read-Host "Enter the file pattern to the .DOCX file(s)" }
|
|
|
|
|
|
|
|
|
|
Write-Host "⏳ Searching for pandoc..."
|
|
|
|
|
$null = (pandoc --version)
|
|
|
|
|
if ($lastExitCode -ne "0") { throw "Can't execute 'pandoc' - make sure it's installed and available" }
|
|
|
|
|
|
|
|
|
|
Write-Host "⏳ Converting..."
|
|
|
|
|
gci -r -i $FilePattern | foreach {
|
|
|
|
|
$TargetPath = $_.directoryname + "\" + $_.basename + ".md"
|
2023-05-26 09:39:57 +02:00
|
|
|
|
& pandoc -f docx -s $_.name -o $TargetPath
|
2023-04-11 22:28:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
2024-10-01 13:37:53 +02:00
|
|
|
|
"✅ converted in $Elapsed sec"
|
2023-04-11 22:28:51 +02:00
|
|
|
|
exit 0 # success
|
|
|
|
|
} catch {
|
|
|
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
|
|
|
exit 1
|
|
|
|
|
}
|