Created
September 17, 2011 10:31
-
-
Save nightroman/1223828 to your computer and use it in GitHub Desktop.
Invoke-Build tasks for markdown files (using MarkdownSharp)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Invoke-Build tasks for markdown files (using MarkdownSharp) | |
# <https://gist.github.com/1223828> | |
<# | |
Task: Convert markdown files to HTML files (using MarkdownSharp). | |
Requires: | |
* MarkdownSharp.dll and its environment variable $env:MarkdownSharp | |
* NuGet install MarkdownDeep.NET | |
* https://github.com/toptensoftware/MarkdownDeep | |
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 { | |
Add-Type -Path $env:MarkdownSharp | |
$Markdown = New-Object MarkdownSharp.Markdown | |
} | |
process { | |
[System.IO.File]::WriteAllText($2, @" | |
<html><title>$([System.IO.Path]::GetFileNameWithoutExtension($_))</title><body> | |
$($Markdown.Transform(([IO.File]::ReadAllText($_)))) | |
</body></html> | |
"@, [System.Text.Encoding]::UTF8) | |
} | |
} | |
<# | |
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