mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-03-29 08:06:51 +01:00
Add convert-md2html.ps1
This commit is contained in:
parent
9449cb4ea7
commit
d300bd034b
@ -1 +1,39 @@
|
|||||||
gci -r -i *.docx |foreach{$md=$_.directoryname+"\"+$_.basename+".md";pandoc -f docx -s $_.name -o $md}
|
<#
|
||||||
|
.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"
|
||||||
|
pandoc -f docx -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
|
||||||
|
}
|
||||||
|
@ -1 +1,3 @@
|
|||||||
gci -r -i *.md |foreach{$docx=$_.directoryname+"\"+$_.basename+".docx";pandoc -f markdown -s --citeproc $_.name -o $docx}
|
|
||||||
|
|
||||||
|
gci -r -i *.md |foreach{$docx=$_.directoryname+"\"+$_.basename+".docx";pandoc -f markdown -s --citeproc $_.name -o $docx}
|
||||||
|
38
Scripts/convert-md2html.ps1
Normal file
38
Scripts/convert-md2html.ps1
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<#
|
||||||
|
.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
|
||||||
|
}
|
@ -34,9 +34,9 @@ function Convert-PowerShellToBatch
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($Filepattern -eq "") { $Filepattern = read-host "Enter path to the PowerShell script(s)" }
|
if ($Filepattern -eq "") { $Filepattern = Read-Host "Enter path to the PowerShell script(s)" }
|
||||||
|
|
||||||
$Files = get-childItem -path "$Filepattern"
|
$Files = Get-ChildItem -path "$Filepattern"
|
||||||
foreach ($File in $Files) {
|
foreach ($File in $Files) {
|
||||||
Convert-PowerShellToBatch "$File"
|
Convert-PowerShellToBatch "$File"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user