Files
akmon/md2pdf_mermaid.bat
2026-01-20 08:04:15 +08:00

45 lines
1021 B
Batchfile

@echo off
REM Markdown to PDF with Mermaid support using pre-rendering
REM Usage: md2pdf_mermaid.bat input.md output.pdf
if "%~2"=="" (
echo Usage: %0 input.md output.pdf
exit /b 1
)
set INPUT=%~1
set OUTPUT=%~2
echo Converting %INPUT% to %OUTPUT% with Mermaid pre-rendering...
REM Create temporary directory for processed files
set TEMP_DIR=%TEMP%\mermaid_temp_%RANDOM%
mkdir "%TEMP_DIR%"
REM Copy input file to temp directory
copy "%INPUT%" "%TEMP_DIR%\input.md"
REM Change to temp directory and process
cd /d "%TEMP_DIR%"
REM Use mermaid-filter to pre-process the markdown
pandoc "input.md" --filter mermaid-filter -t markdown -o "processed.md"
REM Convert to PDF using pandoc
pandoc "processed.md" -o "%OUTPUT%"
REM Copy output back to original directory
if exist "%OUTPUT%" (
copy "%OUTPUT%" "%~dp0%OUTPUT%"
)
REM Clean up
cd /d "%~dp0"
rmdir /s /q "%TEMP_DIR%"
if %errorlevel% equ 0 (
echo Conversion completed successfully!
) else (
echo Conversion failed!
exit /b %errorlevel%
)