Skip to content

Instantly share code, notes, and snippets.

@pohatu
Created July 1, 2013 19:38
Show Gist options
  • Save pohatu/5903868 to your computer and use it in GitHub Desktop.
Save pohatu/5903868 to your computer and use it in GitHub Desktop.
Use the GitHub markdown service to convert md to html via powershell.
[CmdletBinding()] Param (
[Parameter(Position = 0, Mandatory = $True, ValueFromPipelineByPropertyName = $True)]
[ValidateNotNullOrEmpty()]
[Alias('FullName')]
[String]
$filePath
)
function ConvertFrom-md($mdText){
$response = Invoke-WebRequest -Uri 'https://api.github.com/markdown/raw' -Method Post -body "$mdText" -ContentType "text/plain"
return $response.Content
}
#get the full path
$fullPath = Resolve-Path $filePath
#Get Text
$mdt = [String]::Join([environment]::NewLine, (Get-Content $fullPath)); #Get-Content loses linebreaks for some reason.
#Convert And Save to a temp file (warning, will overwrite)
(ConvertFrom-md $mdt) | Out-File $env:TEMP\markdown.html
#Launch in browser
& start iexplore $env:temp\markdown.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment