2023-07-29 10:34:04 +02:00
|
|
|
*convert-md2html.ps1*
|
|
|
|
================
|
2023-05-26 12:20:18 +02:00
|
|
|
|
|
|
|
This PowerShell script converts Markdown file(s) into HTML.
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Parameters
|
|
|
|
----------
|
2023-05-26 12:20:18 +02:00
|
|
|
```powershell
|
2023-07-29 10:15:44 +02:00
|
|
|
PS> ./convert-md2html.ps1 [[-FilePattern] <String>] [<CommonParameters>]
|
2023-05-26 12:20:18 +02:00
|
|
|
|
|
|
|
-FilePattern <String>
|
|
|
|
Specifies the file pattern to the Markdown file(s)
|
|
|
|
|
|
|
|
Required? false
|
|
|
|
Position? 1
|
|
|
|
Default value
|
|
|
|
Accept pipeline input? false
|
|
|
|
Accept wildcard characters? false
|
|
|
|
|
|
|
|
[<CommonParameters>]
|
|
|
|
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
|
|
|
|
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
|
|
|
|
```
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Example
|
|
|
|
-------
|
2023-05-26 12:20:18 +02:00
|
|
|
```powershell
|
2023-08-06 21:36:33 +02:00
|
|
|
PS> ./convert-md2html.ps1 *.md
|
2023-05-26 12:20:18 +02:00
|
|
|
|
|
|
|
```
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Notes
|
|
|
|
-----
|
2023-05-26 12:20:18 +02:00
|
|
|
Author: Markus Fleschutz | License: CC0
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Related Links
|
|
|
|
-------------
|
2023-05-26 12:20:18 +02:00
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Script Content
|
|
|
|
--------------
|
2023-05-26 12:20:18 +02:00
|
|
|
```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
|
2023-08-06 21:36:33 +02:00
|
|
|
PS> ./convert-md2html.ps1 *.md
|
2023-05-26 12:20:18 +02:00
|
|
|
.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"
|
2023-12-07 20:24:45 +01:00
|
|
|
pandoc --standalone --template "$PSScriptRoot/../data/templates/template.html" -s $_.name -o $TargetPath
|
2023-05-26 12:20:18 +02:00
|
|
|
}
|
|
|
|
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
|
|
|
"✔️ converted in $Elapsed sec"
|
|
|
|
exit 0 # success
|
|
|
|
} catch {
|
|
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2024-01-03 12:11:22 +01:00
|
|
|
*(generated by convert-ps2md.ps1 using the comment-based help of convert-md2html.ps1 as of 01/03/2024 12:10:45)*
|