127 lines
No EOL
4.1 KiB
Batchfile
127 lines
No EOL
4.1 KiB
Batchfile
@echo off
|
|
SETLOCAL ENABLEDELAYEDEXPANSION
|
|
|
|
SET DEFAULT_PAGE_WIDTH=152.4
|
|
SET DEFAULT_PAGE_HEIGHT=457.2
|
|
SET DEFAULT_ZOOM=0.265
|
|
SET DEFAULT_CHARS_PER_PAGE=3000
|
|
SET CSS_FILE=OD.css
|
|
SET CSS_FOLDER=OD_css
|
|
SET KEEP_HTML=0
|
|
|
|
IF EXIST "%CSS_FOLDER%\%CSS_FILE%" (
|
|
SET CSS_PATH=%CSS_FOLDER%\%CSS_FILE%
|
|
) ELSE (
|
|
echo CSS not found
|
|
pause
|
|
exit /b 1
|
|
)
|
|
|
|
echo Converting Markdown to SVG (auto page breaks)
|
|
echo.
|
|
|
|
FOR /R %%F IN (*.md) DO (
|
|
CALL :PROCESS_FILE "%%F"
|
|
)
|
|
|
|
echo ============================================
|
|
echo Complete
|
|
echo ============================================
|
|
pause
|
|
GOTO :EOF
|
|
|
|
:PROCESS_FILE
|
|
SET "MDFILE=%~1"
|
|
SET "BASENAME=%~n1"
|
|
SET "FILEPATH=%~dp1"
|
|
SET "HTML_FILE=!FILEPATH!!BASENAME!.html"
|
|
SET "SVG_MULTI=!FILEPATH!!BASENAME!-1.svg"
|
|
|
|
echo ============================================
|
|
echo Checking: %~nx1
|
|
echo ============================================
|
|
|
|
REM Determine which SVG file to check
|
|
SET "SVG_TO_CHECK="
|
|
IF EXIST "!SVG_MULTI!" (
|
|
SET "SVG_TO_CHECK=!SVG_MULTI!"
|
|
echo Multi SVG exists
|
|
) ELSE (
|
|
echo No SVG exists - will convert
|
|
)
|
|
|
|
REM Use PowerShell to compare timestamps
|
|
SET "SKIP=0"
|
|
IF DEFINED SVG_TO_CHECK (
|
|
FOR /F %%R IN ('powershell -NoProfile -Command "if ((Get-Item '%MDFILE%').LastWriteTime -gt (Get-Item '!SVG_TO_CHECK!').LastWriteTime) { Write-Output 'NEWER' } else { Write-Output 'OLDER' }"') DO SET "RESULT=%%R"
|
|
|
|
FOR %%M IN ("%MDFILE%") DO SET "MD_TIME=%%~tM"
|
|
FOR %%S IN ("!SVG_TO_CHECK!") DO SET "SVG_TIME=%%~tS"
|
|
echo MD timestamp: !MD_TIME!
|
|
echo SVG timestamp: !SVG_TIME!
|
|
|
|
IF "!RESULT!"=="OLDER" (
|
|
echo DECISION: SVG is newer - SKIPPING
|
|
SET "SKIP=1"
|
|
) ELSE (
|
|
echo DECISION: MD is newer - WILL CONVERT
|
|
)
|
|
)
|
|
|
|
IF "!SKIP!"=="1" (
|
|
echo STATUS: SKIPPED
|
|
echo.
|
|
GOTO :EOF
|
|
)
|
|
|
|
echo STATUS: CONVERTING
|
|
echo ============================================
|
|
|
|
REM Extract YAML settings using PowerShell (ignores HTML comments)
|
|
SET "PAGE_WIDTH=!DEFAULT_PAGE_WIDTH!"
|
|
SET "PAGE_HEIGHT=!DEFAULT_PAGE_HEIGHT!"
|
|
SET "ZOOM=!DEFAULT_ZOOM!"
|
|
SET "CHARS_PER_PAGE=!DEFAULT_CHARS_PER_PAGE!"
|
|
|
|
FOR /F "usebackq delims=" %%V IN (`powershell -NoProfile -Command "$content = Get-Content '%MDFILE%' -Raw; if ($content -match '(?s)^---\r?\n(.*?)\r?\n---') { $yaml = $matches[1]; if ($yaml -match 'page-width:\s*(\S+)') { $matches[1] } }"`) DO SET "PAGE_WIDTH=%%V"
|
|
|
|
FOR /F "usebackq delims=" %%V IN (`powershell -NoProfile -Command "$content = Get-Content '%MDFILE%' -Raw; if ($content -match '(?s)^---\r?\n(.*?)\r?\n---') { $yaml = $matches[1]; if ($yaml -match 'page-height:\s*(\S+)') { $matches[1] } }"`) DO SET "PAGE_HEIGHT=%%V"
|
|
|
|
FOR /F "usebackq delims=" %%V IN (`powershell -NoProfile -Command "$content = Get-Content '%MDFILE%' -Raw; if ($content -match '(?s)^---\r?\n(.*?)\r?\n---') { $yaml = $matches[1]; if ($yaml -match 'zoom:\s*(\S+)') { $matches[1] } }"`) DO SET "ZOOM=%%V"
|
|
|
|
FOR /F "usebackq delims=" %%V IN (`powershell -NoProfile -Command "$content = Get-Content '%MDFILE%' -Raw; if ($content -match '(?s)^---\r?\n(.*?)\r?\n---') { $yaml = $matches[1]; if ($yaml -match 'chars-per-page:\s*(\S+)') { $matches[1] } }"`) DO SET "CHARS_PER_PAGE=%%V"
|
|
|
|
echo Settings: !PAGE_WIDTH!mm x !PAGE_HEIGHT!mm, zoom: !ZOOM!, chars/page: !CHARS_PER_PAGE!
|
|
|
|
echo [0/3] Auto-inserting page breaks
|
|
powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0convert_md_to_svg_html_only_dependency.ps1" "%MDFILE%" "auto-insert-breaks" "!CHARS_PER_PAGE!"
|
|
IF ERRORLEVEL 1 (
|
|
echo ERROR: Failed to insert page breaks
|
|
GOTO :EOF
|
|
)
|
|
echo Page breaks inserted
|
|
|
|
echo [1/3] Markdown to HTML
|
|
pandoc "%MDFILE%" -s --embed-resources -c "!CSS_PATH!" -o "!HTML_FILE!"
|
|
IF ERRORLEVEL 1 (
|
|
echo ERROR: Pandoc failed
|
|
GOTO :EOF
|
|
)
|
|
echo HTML created
|
|
|
|
echo [2/3] Creating SVGs from page breaks
|
|
powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0convert_md_to_svg_html_only_dependency.ps1" "!HTML_FILE!" "!FILEPATH!!BASENAME!" "!PAGE_WIDTH!" "!PAGE_HEIGHT!" "!ZOOM!"
|
|
IF ERRORLEVEL 1 (
|
|
echo ERROR: Failed to create SVGs
|
|
GOTO :EOF
|
|
)
|
|
|
|
echo [3/3] Cleanup
|
|
IF %KEEP_HTML%==0 (
|
|
IF EXIST "!HTML_FILE!" del "!HTML_FILE!" 2>nul
|
|
)
|
|
|
|
echo Done with %~nx1
|
|
echo.
|
|
|
|
GOTO :EOF |