vault backup: 2026-01-09 12:12:53
This commit is contained in:
48
Documents/Arbeit/IFN/Programmieren WiSe 25 26/Misc/convert.sh
Executable file
48
Documents/Arbeit/IFN/Programmieren WiSe 25 26/Misc/convert.sh
Executable file
@@ -0,0 +1,48 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Pandoc Markdown to PDF conversion script
|
||||
# Usage: ./convert.sh <input_file> <output_file>
|
||||
|
||||
# Check if correct number of arguments provided
|
||||
if [ $# -ne 2 ]; then
|
||||
echo "Usage: $0 <input_file> <output_file>"
|
||||
echo "Example: $0 ../Time\ Table.md ../Time\ Table.pdf"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
INPUT_FILE="$1"
|
||||
OUTPUT_FILE="$2"
|
||||
|
||||
# Check if input file exists
|
||||
if [ ! -f "$INPUT_FILE" ]; then
|
||||
echo "Error: Input file '$INPUT_FILE' not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get the directory where the script is located
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
# Convert markdown to PDF
|
||||
pandoc "$INPUT_FILE" \
|
||||
-f markdown+wikilinks_title_after_pipe \
|
||||
-t html \
|
||||
-c "$SCRIPT_DIR/print.css" \
|
||||
-s \
|
||||
-M title="Time Table" \
|
||||
--lua-filter="$SCRIPT_DIR/image-filter.lua" \
|
||||
--pdf-engine=wkhtmltopdf \
|
||||
--pdf-engine-opt=--footer-center \
|
||||
--pdf-engine-opt="Author: Phil Keier - $(date +'%A, %d %B %Y - %H:%M')" \
|
||||
--pdf-engine-opt=--footer-font-size \
|
||||
--pdf-engine-opt=10 \
|
||||
-o "$OUTPUT_FILE"
|
||||
|
||||
# Check if conversion was successful
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "✓ PDF successfully created: $OUTPUT_FILE"
|
||||
tdf "$OUTPUT_FILE"
|
||||
exit 0
|
||||
else
|
||||
echo "✗ Error during PDF conversion"
|
||||
exit 1
|
||||
fi
|
||||
@@ -0,0 +1,28 @@
|
||||
-- Filter to remove image alt text display
|
||||
function Image(elem)
|
||||
-- Clear all caption/alt text
|
||||
elem.caption = {}
|
||||
elem.attr.attributes = {}
|
||||
return elem
|
||||
end
|
||||
|
||||
function Para(elem)
|
||||
-- If paragraph contains only an image, keep it
|
||||
if #elem.content == 1 and elem.content[1].t == "Image" then
|
||||
return elem
|
||||
end
|
||||
|
||||
-- Remove any standalone text that looks like alt text (common filenames)
|
||||
if #elem.content == 1 and elem.content[1].t == "Str" then
|
||||
local text = elem.content[1].text
|
||||
-- List of common image extensions
|
||||
local image_exts = { "png", "jpg", "jpeg", "gif", "svg", "webp", "bmp" }
|
||||
for _, ext in ipairs(image_exts) do
|
||||
if text:lower():match("%." .. ext .. "$") then
|
||||
return {} -- Remove this paragraph
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return elem
|
||||
end
|
||||
@@ -1,55 +1,209 @@
|
||||
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Mono:wght@400;700&display=swap');
|
||||
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Mono:wght@100..900&family=Noto+Sans:ital,wght@0,100..900;1,100..900&family=Roboto:ital,wght@0,100..900;1,100..900&display=swap');
|
||||
|
||||
@page {
|
||||
size: A4;
|
||||
margin: 1.5cm;
|
||||
|
||||
/* Add page numbers at bottom */
|
||||
@bottom-right {
|
||||
content: "Page " counter(page);
|
||||
font-family: "Noto Sans Mono", monospace;
|
||||
font-size: 10pt;
|
||||
}
|
||||
}
|
||||
/* Print stylesheet for Pandoc PDF conversion - German University Standards */
|
||||
|
||||
/* Base styling */
|
||||
body {
|
||||
font-family: "Helvetica", Arial, sans-serif;
|
||||
font-family: 'Roboto', sans-serif;
|
||||
font-size: 12pt;
|
||||
line-height: 1.5;
|
||||
color: #000;
|
||||
background: #fff;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
text-align: justify;
|
||||
hyphens: auto;
|
||||
-webkit-hyphens: auto;
|
||||
-moz-hyphens: auto;
|
||||
}
|
||||
|
||||
h1,h2 {
|
||||
text-align: center;
|
||||
margin: 0 0 0.5cm 0;
|
||||
font-size: 24pt;
|
||||
page-break-before: always;
|
||||
/* Title - hide it */
|
||||
h1.title {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* Headings */
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
margin-top: 1em;
|
||||
margin-bottom: 0.5em;
|
||||
font-weight: bold;
|
||||
color: #000;
|
||||
page-break-after: avoid;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 18pt;
|
||||
border-bottom: 1pt solid #000;
|
||||
padding-bottom: 0.3em;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 18pt;
|
||||
font-size: 14pt;
|
||||
margin-top: 1.2em;
|
||||
}
|
||||
|
||||
h1,h2:first-of-type {
|
||||
page-break-before: avoid;
|
||||
h3 {
|
||||
font-size: 12pt;
|
||||
}
|
||||
|
||||
/* Table height: page height minus top/bottom margins and header estimate */
|
||||
/* Paragraphs and text */
|
||||
p {
|
||||
margin: 1em 0;
|
||||
orphans: 3;
|
||||
widows: 3;
|
||||
text-align: justify;
|
||||
hyphens: auto;
|
||||
-webkit-hyphens: auto;
|
||||
-moz-hyphens: auto;
|
||||
}
|
||||
|
||||
/* Links - visible but not underlined */
|
||||
a {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a[href]::after {
|
||||
content: "";
|
||||
}
|
||||
|
||||
/* Tables */
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
table-layout: fixed;
|
||||
border: 1pt solid #000;
|
||||
|
||||
/* A4 height 29.7cm - margins 3cm - header 2cm ≈ 24.7cm */
|
||||
height: 22.7cm;
|
||||
margin: 1em 0;
|
||||
page-break-inside: avoid;
|
||||
}
|
||||
|
||||
th, td {
|
||||
border: 0.8pt solid #000;
|
||||
text-align: center;
|
||||
border: 1pt solid #999;
|
||||
padding: 4pt;
|
||||
text-align: left;
|
||||
vertical-align: middle;
|
||||
padding: 0;
|
||||
text-align: justify;
|
||||
hyphens: auto;
|
||||
-webkit-hyphens: auto;
|
||||
-moz-hyphens: auto;
|
||||
}
|
||||
|
||||
/* Tight spacing for first column (dates) */
|
||||
th:first-child,
|
||||
td:first-child {
|
||||
padding: 2pt 3pt;
|
||||
text-align: center;
|
||||
width: 8%;
|
||||
font-size: 10pt;
|
||||
}
|
||||
|
||||
th {
|
||||
background-color: #f5f5f5;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* Lists */
|
||||
ul, ol {
|
||||
margin: 1em 0;
|
||||
padding-left: 2em;
|
||||
}
|
||||
|
||||
li {
|
||||
margin: 0.5em 0;
|
||||
text-align: justify;
|
||||
hyphens: auto;
|
||||
-webkit-hyphens: auto;
|
||||
-moz-hyphens: auto;
|
||||
}
|
||||
|
||||
/* Code blocks */
|
||||
pre {
|
||||
background-color: #f5f5f5;
|
||||
border: 1pt solid #ddd;
|
||||
padding: 10pt;
|
||||
overflow-x: auto;
|
||||
page-break-inside: avoid;
|
||||
font-family: 'Noto Sans Mono', monospace;
|
||||
font-size: 10pt;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: 'Noto Sans Mono', monospace;
|
||||
font-size: 0.9em;
|
||||
background-color: #f5f5f5;
|
||||
padding: 2pt 4pt;
|
||||
}
|
||||
|
||||
/* Blockquotes */
|
||||
blockquote {
|
||||
margin-left: 2em;
|
||||
margin-right: 0;
|
||||
padding-left: 1em;
|
||||
border-left: 3pt solid #999;
|
||||
color: #666;
|
||||
page-break-inside: avoid;
|
||||
text-align: justify;
|
||||
hyphens: auto;
|
||||
-webkit-hyphens: auto;
|
||||
-moz-hyphens: auto;
|
||||
}
|
||||
|
||||
/* Footnotes */
|
||||
.footnotes {
|
||||
margin-top: 2em;
|
||||
padding-top: 1em;
|
||||
border-top: 1pt solid #000;
|
||||
font-size: 10pt;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.footnotes ol {
|
||||
padding-left: 1.5em;
|
||||
}
|
||||
|
||||
.footnotes li {
|
||||
margin: 0.5em 0;
|
||||
}
|
||||
|
||||
/* Images */
|
||||
img {
|
||||
display: block;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
/* Page breaks */
|
||||
.page-break {
|
||||
page-break-after: always;
|
||||
}
|
||||
|
||||
/* Print media queries - German university standards */
|
||||
@page {
|
||||
margin-top: 2.5cm;
|
||||
margin-bottom: 2.5cm;
|
||||
margin-left: 2.5cm;
|
||||
margin-right: 4.5cm;
|
||||
|
||||
@footnote {
|
||||
border-top: 1pt solid #000;
|
||||
padding-top: 0.5em;
|
||||
margin-top: 1em;
|
||||
}
|
||||
}
|
||||
|
||||
@media print {
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
/* Avoid page breaks inside elements */
|
||||
h1, h2, h3, h4, h5, h6,
|
||||
table, pre, blockquote {
|
||||
page-break-inside: avoid;
|
||||
}
|
||||
|
||||
/* Prevent widows and orphans */
|
||||
p {
|
||||
orphans: 3;
|
||||
widows: 3;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user