@echo off setlocal set _input=%~1 set _output=%~2 if "%_input%"=="" ( call :DisplayHelp endlocal goto :EOF ) if "%_input%"=="help" ( call :DisplayHelp endlocal goto :EOF ) if "%_output%"=="" ( call :DisplayHelp endlocal goto :EOF ) call :GetBatchFileDirectory _myDir call :FindPandoc PANDOC_EXE if not defined PANDOC_EXE ( call :DisplayToolsError endlocal goto :EOF ) "%PANDOC_EXE%" -f markdown -t html5 --template=html5.template --table-of-contents -s -o "%_output%" "%_input%" endlocal goto :EOF :GetBatchFileDirectory varName setlocal EnableExtensions EnableDelayedExpansion set _dir=%~dp0 set _dir=%_dir:~0,-1% endlocal & set %1=%_dir% goto :EOF :: :: DisplayHelp :: :: Display the usage information for this batch file. :: :DisplayHelp echo Usage: %0 [input] [output] echo. echo Converts the markdown file [input] to HTML [output] using Pandoc or Markdown.pl. exit /b 0 goto :EOF :: :: DisplayToolsError :: :: Called when Pandoc is not found. :: Displays an error message indicating that Pandoc is required. :: :DisplayToolsError echo Pandoc was not found. echo. echo Pandoc must be installed for this batch file to function. echo Pandoc can be found at http://pandoc.org/. exit /b 0 goto :EOF :: :: FindPandoc :: :: Attempts to find pandoc.exe. If Pandoc is found, it sets the environment variable specified by the :: first parameter of the function to the location where pandoc.exe was found. :: :FindPandoc setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION set _candidate=%LOCALAPPDATA%\Pandoc\pandoc.exe if exist "%_candidate%" goto FoundPandoc set _candidate=%ProgramFiles%\Pandoc\pandoc.exe if exist "%_candidate%" goto FoundPandoc set _candidate=%ProgramFiles(x86)%\Pandoc\pandoc.exe if exist "%_candidate%" goto FoundPandoc for %%f in (pandoc.exe) do set _candidate=%%~$PATH:f if exist "%_candidate%" goto FoundPandoc exit /b 1 :FoundPandoc endlocal & set %1=%_candidate% exit /b 0 goto :EOF