Skip to content

Instantly share code, notes, and snippets.

@nightroman
Created September 18, 2011 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nightroman/1225405 to your computer and use it in GitHub Desktop.
Save nightroman/1225405 to your computer and use it in GitHub Desktop.
Invoke-Build tasks for markdown files (using Markdown.pl)
# Invoke-Build tasks for markdown files (using Markdown.pl)
# <https://gist.github.com/1225405>
<#
Task: Convert markdown files to HTML files (using Markdown.pl).
Requires:
* Perl script Markdown.pl <http://daringfireball.net/projects/markdown/>
* Either perl executable in the path or the predefined alias 'perl', e.g.:
Set-Alias perl "C:\Program Files\Git\bin\perl.exe"
Inputs: Markdown files in the current location.
Outputs: *.htm files with same base names as input.
#>
task ConvertMarkdown -Partial -Inputs {Get-Item *.md, *.markdown} -Outputs {process{[System.IO.Path]::ChangeExtension($_, 'htm')}} {
begin {
assert (Get-Command perl -ErrorAction 0) "Command 'perl' is not found."
$script = Get-Command Markdown.pl -ErrorAction 0
assert $script "Script 'Markdown.pl' is not found."
$script = $script.Definition
}
process {
perl $script $_ | Set-Content -LiteralPath $2
}
}
<#
Task: Remove HTML files presumably created by ConvertMarkdown.
All *.htm files having *.md or *.markdown pairs are removed.
#>
task RemoveMarkdownHtml {
foreach($_ in Get-Item *.md, *.markdown) {
$path = [System.IO.Path]::ChangeExtension($_.FullName, 'htm')
if (Test-Path -LiteralPath $path) { Remove-Item -LiteralPath $path }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment