#!/bin/bash file=parkinson template=../TEMPLATES/mslide #help="$template/help.fr" # which HTML to PDF converter usePrince=false # PDF Options coverPage=false newPage=true color=false titleCount=true ownSlideCss= ownDocCss= usePrince=false # End of configuration # preset binaries AWK=awk SED=sed DATA_URI=data-uri PRINCE=prince WEASYPRINT=weasyprint resourcePath=".:$template" PATH="$template:$PATH" # if we run on Windows set what we have to launch if [ "$OS" = "Windows_NT" ] then PATH="$PATH;;C:\Program Files (x86)\Prince\engine\bin;$PATH;$template" AWK="$template/goawk.exe" SED="$template/sed-go.exe" resourcePath=".;$template" fi # extract lang from markdown file lang=$($AWK '{ if ( $1 == "lang:" ) { print $2 exit; } }' "$file.md") # This don't work for dash, use sed! # lang="${lang:0:2}" lang=$(echo $lang | $SED 's/^\(..\).*/\1/') help="$template/help.$lang" # preset for PDF coverpage=empty.css newpage=empty.css ownslidecss=empty.css owndoccss=empty.css colorcss=empty.css titlecount=empty.css # now set the correxponding variables if [ "$coverPage" = "true" ]; then coverpage=cover.css fi if [ "$newPage" = "true" ]; then newpage=newpage.css fi if [ "$color" = "true" ]; then colorcss=pygments.css fi if [ "$titleCount" = "true" ]; then titlecount=h-counter.css fi if [ "$ownSlideCss" != "" ]; then ownslidecss="$ownSlideCss" fi if [ "$ownDocCss" != "" ]; then owndoccss="$ownDocCss" fi cover() { awk -F ' ' 'BEGIN { level=0; cover=0; } { if ( $1 == "" ) { level--; } if ( $1 == "\n", $2); } else { if ( $1 == "" && level == 0 ) { printf("\n"); } else { if ( $1 == "" ) [ ; } else { print } } } } }' } altalt() { sed -e 's/\(alt="[^"]*"*\) \(alt="[^"]*"\)/\1/' -e 's/figcaption aria-hidden="true"/figcaption/' } removeLinks() { sed 's/href="#cb[0-9][0-9a-z-]*"//' } pandoc -L "$template/convertHeader.lua" \ -i "$file.md" \ --resource-path ".:$template" \ --to html5 \ --section-div \ --template mslide.html \ --include-in-header stb.html \ --include-in-header main.css \ --include-in-header theme.css \ --include-in-header color.css \ --include-in-header anim.css \ --include-in-header ste.html \ --include-in-header jsb.html \ --include-in-header mslide.js \ --include-in-header jse.html \ --include-before-body $help |\ removeLinks |data-uri -i - -o "$file-slide.html" #sed 's/href="#cb[0-9][0-9a-z-]*"//' > "$file-slide.html" # TODO substitute first occurence if
to
ad # last occurence of
to pandoc -i "$file.md" \ --section-div \ --resource-path ".:$template" \ --to html5 \ --template mweb.html \ --highlight-style pygments \ --section-divs \ --include-in-header stb.html \ --include-in-header docmain.css \ --include-in-header pygments.css \ --include-in-header h-counter.css \ --include-in-header ste.html |\ cover | altalt | removeLinks |\ data-uri -i - -o "$file.html" weasyprint "$file.html" "$file.pdf" #/home/jj/venv/bin/weasyprint --pdf-version 1.7 --pdf-variant pdf/ua-1 "$file.html" "$file.pdf"