INITIAL COMMIT
This commit is contained in:
parent
7a7bafd7af
commit
46536e2b52
7 changed files with 283 additions and 0 deletions
BIN
pandocPipeline/Logo.png
Normal file
BIN
pandocPipeline/Logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 21 KiB |
27
pandocPipeline/README.md
Normal file
27
pandocPipeline/README.md
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
# Pandoc Pipeline
|
||||||
|
|
||||||
|
Einfache Rendering Pipeline für Pandoc.
|
||||||
|
Optimiert für die Konvertierung von Markdown zu PDF oder zu DOCX.
|
||||||
|
Diese beiden Ausgangsformate werden während des Renderingsprozesses mit einem Branding versehen.
|
||||||
|
|
||||||
|
Zur Verwendung der Pipeline muss installiert sein:
|
||||||
|
pdflatex
|
||||||
|
pandoc
|
||||||
|
git
|
||||||
|
|
||||||
|
:warning: Umgebungsvariablen setzen nicht vergessen :warning:
|
||||||
|
|
||||||
|
:seedling: :seedling: :seedling:
|
||||||
|
git liefert bei Installation im Ordner /bin eine Sammlung von unix-Kommandos mit.
|
||||||
|
Dieser Pfad muss auch zu den Umgebungsvariablen hinzugefügt werden.
|
||||||
|
:seedling: :seedling: :seedling:
|
||||||
|
|
||||||
|
## Verwendung
|
||||||
|
|
||||||
|
Für eine universelle Verwendung sollte auch dieser Pfad zu den Umgebungsvariablen hinzugefügt werden.
|
||||||
|
|
||||||
|
Konvertierung md -> pdf
|
||||||
|
`pandocPipeline -u "Dokumentbearbeiter" -t "Dokumententitel" -f dateiname -e pdf`
|
||||||
|
|
||||||
|
Konvertierung md -> docx
|
||||||
|
`pandocPipeline -f dateiname -e docx`
|
||||||
32
pandocPipeline/body.sed
Normal file
32
pandocPipeline/body.sed
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
/\$\$/ {
|
||||||
|
N;
|
||||||
|
/\\begin\{align\}/ {
|
||||||
|
s/\$\$//;
|
||||||
|
p;
|
||||||
|
d;
|
||||||
|
}
|
||||||
|
/\\newcommand/ {
|
||||||
|
N;
|
||||||
|
d;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/\\end\{align\}/ {
|
||||||
|
N;
|
||||||
|
/\$\$/ {
|
||||||
|
s/\$\$//;
|
||||||
|
p;
|
||||||
|
d;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s/lightgreen/Lime/g;
|
||||||
|
s/\{green/\{Green/g;
|
||||||
|
s/\{yellow/\{Goldenrod/g;
|
||||||
|
s/\{darkorange/\{DarkOrange/g;
|
||||||
|
s/:::/::: /g;
|
||||||
|
s/\\circ \- \\bullet/\\;\\laplace\\;/g;
|
||||||
|
s/\{align/\{align\*/g;
|
||||||
|
s/\\color/\\textcolor/g;
|
||||||
|
s/\*\*<center>/\\begin{center}\\textbf{/g;
|
||||||
|
s/<\/Center>\*\*/}\\end{center}/g;
|
||||||
|
|
||||||
BIN
pandocPipeline/custom-reference.docx
Normal file
BIN
pandocPipeline/custom-reference.docx
Normal file
Binary file not shown.
34
pandocPipeline/header.md
Normal file
34
pandocPipeline/header.md
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
---
|
||||||
|
documentclass: extarticle
|
||||||
|
fontsize: 12pt
|
||||||
|
geometry: margin=2cm
|
||||||
|
papersize: a4
|
||||||
|
header-includes: |
|
||||||
|
\usepackage{pdfpages}
|
||||||
|
\usepackage{trfsigns}
|
||||||
|
\usepackage[breakable]{tcolorbox}
|
||||||
|
\usepackage[compatV3]{fancyhdr}
|
||||||
|
\renewcommand{\contentsname}{Inhaltsverzeichnis}
|
||||||
|
\pagestyle{fancy}
|
||||||
|
\fancyhf{}
|
||||||
|
\setlength{\textheight}{700pt}
|
||||||
|
\setlength{\footskip}{5pt}
|
||||||
|
\setlength{\headheight}{52pt}
|
||||||
|
\rhead{\includegraphics[width=.3\textwidth]{path/to/Logo.png}}
|
||||||
|
\lhead{
|
||||||
|
Current version date: \today \\
|
||||||
|
Editor:
|
||||||
|
Title:
|
||||||
|
}
|
||||||
|
\cfoot{\thepage}
|
||||||
|
\renewcommand{\footrulewidth}{0.4pt}
|
||||||
|
\newtcolorbox{info-box}{colback=cyan!5!white,arc=0pt,outer arc=0pt,colframe=cyan!60!black}
|
||||||
|
\newtcolorbox{warning-box}{colback=orange!5!white,arc=0pt,outer arc=0pt,colframe=orange!80!black}
|
||||||
|
\newtcolorbox{error-box}{colback=red!5!white,arc=0pt,outer arc=0pt,colframe=red!75!black}
|
||||||
|
pandoc-latex-environment:
|
||||||
|
tcolorbox: [box]
|
||||||
|
info-box: [info]
|
||||||
|
warning-box: [warning]
|
||||||
|
error-box: [danger]
|
||||||
|
classoption: svgnames
|
||||||
|
---
|
||||||
131
pandocPipeline/pandocPipeline.bat
Normal file
131
pandocPipeline/pandocPipeline.bat
Normal file
|
|
@ -0,0 +1,131 @@
|
||||||
|
@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
|
||||||
|
|
||||||
|
:error
|
||||||
|
echo An error occured
|
||||||
|
echo Try 'pandocPipeline --help' for more information
|
||||||
|
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
|
||||||
59
pandocPipeline/pandoc_latex_environment.py
Normal file
59
pandocPipeline/pandoc_latex_environment.py
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
"""
|
||||||
|
Pandoc filter for adding LaTeX environement on specific div
|
||||||
|
"""
|
||||||
|
|
||||||
|
from pandocfilters import toJSONFilters, stringify, RawBlock, Para
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
def environment(key, value, format, meta):
|
||||||
|
# Is it a div and the right format?
|
||||||
|
if key == 'Div' and format in ['latex', 'beamer']:
|
||||||
|
|
||||||
|
# Get the attributes
|
||||||
|
[[id, classes, properties], content] = value
|
||||||
|
|
||||||
|
currentClasses = set(classes)
|
||||||
|
|
||||||
|
for environment, definedClasses in getDefined(meta).items():
|
||||||
|
# Is the classes correct?
|
||||||
|
if currentClasses >= definedClasses:
|
||||||
|
if id != '':
|
||||||
|
label = '\n\\label{' + id + '}'
|
||||||
|
else:
|
||||||
|
label = ''
|
||||||
|
|
||||||
|
currentProperties = dict(properties)
|
||||||
|
if 'title' in currentProperties:
|
||||||
|
title = '[' + currentProperties['title'] + ']'
|
||||||
|
else:
|
||||||
|
title = ''
|
||||||
|
|
||||||
|
before = RawBlock('tex', '\\begin{' + environment + '}' + title + label)
|
||||||
|
after = RawBlock('tex', '\\end{' + environment + '}')
|
||||||
|
|
||||||
|
value[1] = [before] + content + [after]
|
||||||
|
break
|
||||||
|
|
||||||
|
def getDefined(meta):
|
||||||
|
# Return the latex-environment defined in the meta
|
||||||
|
if not hasattr(getDefined, 'value'):
|
||||||
|
getDefined.value = {}
|
||||||
|
if 'pandoc-latex-environment' in meta and meta['pandoc-latex-environment']['t'] == 'MetaMap':
|
||||||
|
for environment, classes in meta['pandoc-latex-environment']['c'].items():
|
||||||
|
if classes['t'] == 'MetaList':
|
||||||
|
getDefined.value[environment] = []
|
||||||
|
for klass in classes['c']:
|
||||||
|
string = stringify(klass)
|
||||||
|
if re.match('^[a-zA-Z][\w.:-]*$', string):
|
||||||
|
getDefined.value[environment].append(string)
|
||||||
|
getDefined.value[environment] = set(getDefined.value[environment])
|
||||||
|
return getDefined.value
|
||||||
|
|
||||||
|
def main():
|
||||||
|
toJSONFilters([environment])
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue