#! /bin/bash version=1.0 editor=$USER title= file= ending=tex toc=false open=0 # path to this script script=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd) picture=$script/Logo.png 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 -c, --toc prints a table of content at the start of the document echo -p, --picture changes the default picture to a specified picture relative to current path 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 Examples: echo md -\> pdf : pandocPipeline -f dateiname -e pdf echo md -\> docx : pandocPipeline -f dateiname -e docx echo Author is by default $editor to change the author add the author to the metadata in your markdown file echo Title is by default the filename to change the title add the title to the metadata in your markdown file } Errorfile() { echo No file was given echo Please add a filename to your command echo Try 'pandocPipeline --help' for more information } Open() { xdg-open $file.$ending exit } POSITIONAL_ARGS=() while [[ $# -gt 0 ]]; do case $1 in -f|--file) file="$2" shift 2;; -e|--ending) ending="$2" shift 2;; -v|--version) echo pandocPipeline $version exit;; -p|--picture) picture="$2" shift 2;; -c|--toc) toc=true shift;; -h|--help) Help exit;; --open) open=1 shift;; --) break; esac done if [[ -z "$file" ]]; then Errorfile exit fi title=$file editor=$(grep 'author: .*' $file.md) editor=${editor:8} title=$(grep 'title: .*' $file.md) title=${title:7} if [[ "$ending" == "pdf" ]]; then header=$script/header.md sedfile=$script/body.sed sed -i 's,Editor:.*,Editor: '"$editor"' \\\\,' $header sed -i 's,Title:.*,Title: '"$title"',' $header sed -i 's,textwidth]{.*,textwidth]{'"$picture"'}},' $header if "$toc"; then cat $file.md $header | sed -E -f $sedfile| pandoc --filter pandoc_latex_environment.py --number-sections --toc -i - -o $file.pdf else cat $file.md $header | sed -E -f $sedfile| pandoc --filter pandoc_latex_environment.py --number-sections -i - -o $file.pdf fi [[ $open == "1" ]] && Open || true elif [[ "$ending" == "docx" ]]; then refdoc=$script/custom-reference.docx pandoc $file.md --reference-doc=$refdoc -f markdown -t $ending -s -o $file.$ending [[ $open == "1" ]] && Open || true else pandoc $file.md -f markdown -t $ending -s -o $file.$ending [[ $open == "1" ]] && Open || true fi