mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-15 20:44:17 +01:00
39 lines
1.1 KiB
PowerShell
39 lines
1.1 KiB
PowerShell
|
<#
|
||
|
.SYNOPSIS
|
||
|
Converts Markdown file(s) into HTML
|
||
|
.DESCRIPTION
|
||
|
This PowerShell script converts Markdown file(s) into HTML.
|
||
|
.PARAMETER FilePattern
|
||
|
Specifies the file pattern to the Markdown file(s)
|
||
|
.EXAMPLE
|
||
|
PS> ./convert-md2html *.md
|
||
|
.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 Markdown 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 + ".html"
|
||
|
pandoc -f md -s $_.name -o $TargetPath
|
||
|
}
|
||
|
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||
|
"✔️ converted in $Elapsed sec"
|
||
|
exit 0 # success
|
||
|
} catch {
|
||
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||
|
exit 1
|
||
|
}
|