5
0
Fork 0
hedgedoc2pdf/pandocPipeline/pandocPipeline.bat
2023-06-07 14:58:17 +02:00

126 lines
2.9 KiB
Batchfile

@echo off
::if no arguments given show help
IF "%1"=="" (goto :help)
set editor=%USERNAME%
set title =
set file = none
set ending = tex
::path to this script
set script= %~dp0
set version= 1.0
::parsing arguments
:loop
IF NOT "%1"=="" (
IF "%1"=="-h" (
goto :help
)
IF "%1"=="--help" (
goto :help
)
IF "%1"=="-v" (
goto :version
)
IF "%1"=="--version" (
goto :version
)
IF "%1"=="-u" (
SET editor=%2
SHIFT
)
IF "%1"=="-user" (
SET editor=%2
SHIFT
)
IF "%1"=="-t" (
SET title=%2
SHIFT
)
IF "%1"=="--title" (
SET title=%2
SHIFT
)
IF "%1"=="-f" (
SET file=%2
SHIFT
)
IF "%1"=="--file" (
SET file=%2
SHIFT
)
IF "%1"=="-e" (
SET ending=%2
SHIFT
)
IF "%1"=="--ending" (
SET ending=%2
SHIFT
)
SHIFT
GOTO :loop
)
:program
::check if file to parse was given
IF %file%==none (goto :errorfile)
IF %ending%==pdf (goto :program_tex)
IF %ending%==docx (goto :program_docx) ELSE (goto :program_other)
:program_tex
set header=%script%header.md
set header=%header: =%
set sedfile=%script%body.sed
set sedfile=%sedfile: =%
set picture=%script%Logo.png
set picture=%picture: =%
set picture=%picture:\=/%
set pandocenv=%script%pandoc_latex_environment.py
set pandocenv=%pandocenv: =%
::fill header with appropriate information
sed -i 's,Editor:.*,Editor: '%editor%' \\\\\\\\,' %header%
sed -i 's,Title:.*,Title: '%title%',' %header%
sed -i 's,textwidth]{.*,textwidth]{'%picture%'}},' %header%
::execute pandoc
cat %file%.md %header% | sed -E -f %sedfile%| pandoc --filter %pandocenv% --number-sections --toc -i - -o %file%.pdf
goto :open
:program_docx
set refdoc=%script%custom-reference.docx
set refdoc=%refdoc: =%
pandoc %file%.md --reference-doc=%refdoc% -f markdown -t %ending% -s -o %file%.%ending%
goto :open
:program_other
pandoc %file%.md -f markdown -t %ending% -s -o %file%.%ending%
goto :open
:open
%file%.%ending%
goto :end
:help
echo Tool to convert file from markdown to another format
echo Usage: pandocPipeline [OPTION] [COMMAND]
echo -h, --help show this help screen
echo -f, --file specify filename without extension
echo -e, --ending spefify target file format
echo -u, --user=%USERNAME% enter name of file editor set between "" (only for target format pdf)
echo -t, --title enter title of document set between "" (only for target format pdf)
echo Pipeline is optimized for target format pdf and docx but works with others as well
echo Possible fileformats see: https://pandoc.org/diagram.svgz?v=20230203095535
goto :end
:version
echo pandocPipeline %version%
goto :end
:errorfile
echo No file was given
echo Please add a filename to your command
echo Try 'pandocPipeline --help' for more information
goto :end
:end