Skip to content

Instantly share code, notes, and snippets.

@nightroman
Created September 17, 2011 10:31
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/1223828 to your computer and use it in GitHub Desktop.
Save nightroman/1223828 to your computer and use it in GitHub Desktop.
Invoke-Build tasks for markdown files (using MarkdownSharp)
# 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