diff --git a/pandocPipeline/pandocPipeline.bat b/pandocPipeline/pandocPipeline.bat index 08d4785..1530c05 100644 --- a/pandocPipeline/pandocPipeline.bat +++ b/pandocPipeline/pandocPipeline.bat @@ -7,6 +7,7 @@ set editor=%USERNAME% set title = set file = none set ending = tex +set "_=" ::path to this script set script= %~dp0 set version= 1.0 @@ -26,22 +27,6 @@ IF NOT "%1"=="" ( 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 @@ -64,8 +49,23 @@ IF NOT "%1"=="" ( :program ::check if file to parse was given -IF %file%==none (goto :errorfile) +IF %file%==none (goto :errorfile) ELSE (goto :extract_metadata) +:extract_metadata +set title=%file% +For /F "UseBackQ Tokens=1,*" %%G In ("%file%.md") Do ( + If "%%~G" == "[Title]:" ( + set title=%%H + ) + If "%%~G" == "[Author]:" ( + set editor=%%H + ) +) +set title=%title:~3,-1% +set editor=%editor:~3,-1% +goto :selection + +:selection IF %ending%==pdf (goto :program_tex) IF %ending%==docx (goto :program_docx) ELSE (goto :program_other) @@ -80,8 +80,8 @@ 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,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 @@ -107,10 +107,14 @@ 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 +echo Author is by default %USERNAME% +echo to change the author write follwing in your markdown file +echo [Author]: # (your name) +echo Title is by default the filename +echo to change the title write follwing in your markdown file +echo [Title]: # (document title) goto :end :version