79652677

Date: 2025-06-04 11:47:02
Score: 3
Natty:
Report link

Dude, thanks you pointed me in the right direction:

I had some mermaid syntax error in my .md that made some errors, but i figured it out. In my renderes this was ok, but not during export.

Correct format:
```mermaid

NOT correct
``` mermaid

I made some additional changes for anybody else finding this. A batch converter with some debugging, and the actual converter also with some debugging.

File: markdown_converter_stackoverflow.bat

@echo off
setlocal enabledelayedexpansion

REM ============================================
REM CONFIGURATION VARIABLES - EDIT THESE
REM ============================================
set "AUTO_RUN=true"
set "AUTO_CLOSE=true"

REM AUTO_RUN: Set to "true" to skip all pause statements, "false" for step-by-step
REM AUTO_CLOSE: Set to "true" to close automatically at end, "false" to wait for keypress

REM ============================================
REM SCRIPT START
REM ============================================

echo Starting conversion process...
echo Input file: "%~1"
if /i "%AUTO_RUN%"=="false" pause

REM Check if a file path is provided
if "%~1"=="" (
    echo Please provide a Markdown file path as an argument.
    if /i "%AUTO_CLOSE%"=="false" pause
    exit /b 1
)

REM Get the full path, filename, and directory of the input file
set "fullpath=%~f1"
set "filename=%~n1"
set "filedir=%~dp1"
set "scriptdir=%~dp0"

echo File details:
echo - Full path: %fullpath%
echo - Filename: %filename%
echo - Directory: %filedir%
if /i "%AUTO_RUN%"=="false" pause

REM Create (or recreate) a temporary folder
set "tempfolder=%filedir%%filename%"
if exist "%tempfolder%" rmdir /s /q "%tempfolder%"
mkdir "%tempfolder%"

echo Created temp folder: %tempfolder%

REM Copy images folder if it exists
if exist "%filedir%Figurer" (
    echo Copying Figurer folder to temp directory...
    xcopy "%filedir%Figurer" "%tempfolder%\Figurer\" /E /I /Y
    if %errorlevel% equ 0 (
        echo Images copied successfully
    ) else (
        echo Warning: Failed to copy images
    )
) else (
    echo No Figurer folder found in: %filedir%
)
if /i "%AUTO_RUN%"=="false" pause

REM Run Mermaid-cli to preprocess the Markdown file
echo Processing Markdown file with Mermaid...
call mmdc -i "%fullpath%" --outputFormat=pdf --pdfFit -o "%tempfolder%\%filename%.md"
if %errorlevel% neq 0 (
    echo Error: Mermaid-cli failed with exit code %errorlevel%
    if /i "%AUTO_CLOSE%"=="false" pause
    goto :cleanup
)
echo Mermaid-cli processing complete.
if /i "%AUTO_RUN%"=="false" pause

REM Change to the temporary directory
echo Changing to temporary directory...
pushd "%tempfolder%"
if %errorlevel% neq 0 (
    echo Error: Failed to change to temporary directory
    if /i "%AUTO_CLOSE%"=="false" pause
    goto :cleanup
)
echo Changed to temporary directory successfully.

REM Show what's in the temp directory
echo Contents of temp directory:
dir /b
echo.
if /i "%AUTO_RUN%"=="false" pause

REM Convert the processed Markdown to PDF using Pandoc
echo Converting to PDF...
call pandoc "%filename%.md" -f markdown-implicit_figures -o "..\%filename%.pdf"
if %errorlevel% neq 0 (
    echo Error: Pandoc failed with exit code %errorlevel%
    if /i "%AUTO_CLOSE%"=="false" pause
    popd
    goto :cleanup
)
echo PDF conversion complete.
if /i "%AUTO_RUN%"=="false" pause

REM Change back to the original directory
echo Changing back to original directory...
popd
echo Changed back to original directory.

:cleanup
REM Clean up the temporary folder
echo Cleaning up...
@REM rmdir /s /q "%tempfolder%"

if exist "%filedir%%filename%.pdf" (
    echo Conversion complete. Output file: %filedir%%filename%.pdf
) else (
    echo Error: PDF file was not created.
)

REM Final pause based on AUTO_CLOSE setting
if /i "%AUTO_CLOSE%"=="false" (
    echo Press any key to exit...
    pause >nul
)
file: markdown__batch_conversion_script.bat

@echo off

REM ============================================
REM CONFIGURATION VARIABLES - EDIT THESE
REM ============================================
set "AUTO_RUN=true"
set "AUTO_CLOSE=false"

REM AUTO_RUN: Set to "true" to skip all pause statements, "false" for step-by-step
REM AUTO_CLOSE: Set to "true" to close automatically at end, "false" to wait for keypress

REM ============================================
REM SCRIPT START
REM ============================================

echo ========================================
echo Acts Academy Document Conversion
echo ========================================
echo Configuration: AUTO_RUN=%AUTO_RUN%, AUTO_CLOSE=%AUTO_CLOSE%
echo.

REM Use the working StackOverflow converter
set "CONVERTER=%~dp0markdown_converter_stackoverflow.bat"

echo Converting first document...
call "%CONVERTER%" "Markdown1.md"

echo.
echo Converting second document...
call "%CONVERTER%" "Markdown2.md"

echo.
echo ========================================
echo Conversion completed!
echo ========================================

REM Show what files were created
echo Generated PDF files:
dir /b *.pdf 2>nul || echo No PDF files found

echo.

REM Final pause based on AUTO_CLOSE setting
if /i "%AUTO_CLOSE%"=="false" (
    echo Press any key to exit...
    pause >nul
) else (
    echo Auto-closing in 3 seconds...
    timeout /t 3 >nul
)

Fix files names, and place/run bat file in same directory.

Reasons:
  • Blacklisted phrase (0.5): thanks
  • Blacklisted phrase (1): stackoverflow
  • Blacklisted phrase (1): StackOverflow
  • Whitelisted phrase (-2): i figured it out
  • RegEx Blacklisted phrase (2.5): Please provide
  • Long answer (-1):
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: Daniel