added prettier code blocks #36

Merged
servostar merged 1 commits from feature/pretty-codeblocks into main 2024-07-19 13:09:01 +00:00
3 changed files with 61 additions and 29 deletions

View File

@ -65,6 +65,8 @@
code: (
theme: "res/abb.tmTheme",
font: "FiraCode Nerd Font",
lines: false,
size: 10pt,
tab-size: 4),
link: (
color: ABB-GRAY-02)))

View File

@ -78,7 +78,59 @@
set raw(
tab-size: style.code.tab-size,
theme: style.code.theme)
show raw: set text(font: style.code.font)
show raw: set text(font: style.code.font, size: style.code.size)
show figure.where(kind: raw): it => align(left)[
#let content = it.body
#block(
width: 100%,
fill: ABB-GRAY-06,
stroke: none,
radius: 0.5em,
inset: 0.75em,
clip: false,
{
let (columns, align, make_row) = {
if style.code.lines {(
(auto, 1fr),
(right + top, left),
e => {
let (i, l) = e
let n = i + 1
let n_str = if (calc.rem(n, 1) == 0) or (true and i == 0) { text(font: style.code.font, size: style.code.size, fill: ABB-BLACK, str(n)) } else { none }
(n_str + h(0.5em), raw(lang: content.lang, l))
})
}
else {
( ( 1fr, ),
( left, ),
e => {
let (i, l) = e
raw( lang:content.lang, l)
}
)
}
}
grid(
stroke: none,
columns: columns,
rows: (auto,),
gutter: 0pt,
inset: 0.25em,
align: (col, _) => align.at(col),
fill: ABB-GRAY-06,
..content
.text
.split("\n")
.enumerate()
.map(make_row)
.flatten()
.map(c => if c.has("text") and c.text == "" { v(1em) } else { c })
)
}
)
#v(-1em)
#align(center + top, it.caption)
]
show figure: set block(breakable: true)

View File

@ -5,6 +5,7 @@
#show: dhbw-template.with((
lang: "en",
region: "en",
draft: false,
author: (
name: "Sven Vogel",
semester: 4,
@ -80,6 +81,8 @@ $
#pagebreak()
#lorem(100)
#figure(
```rust
use std::env;
@ -87,37 +90,12 @@ use std::fs::OpenOptions;
use std::io::Write;
fn main() {
// Get the file path from the environment variable
let file_path = match env::var("OUTPUT_FILE") {
Ok(path) => path,
Err(_) => {
eprintln!("Error: OUTPUT_FILE environment variable is not set");
return;
}
};
// Open the file in append mode, create it if it doesn't exist
let mut file = match OpenOptions::new()
.append(true)
.create(true)
.open(&file_path)
{
Ok(file) => file,
Err(e) => {
eprintln!("Error opening file {}: {}", file_path, e);
return;
}
};
// Write "Hello, World" to the file
if let Err(e) = writeln!(file, "Hello, World") {
eprintln!("Error writing to file: {}", e);
} else {
println!("Successfully appended 'Hello, World' to {}", file_path);
}
println!("Hello, World!!!");
}
```, caption: [Some code])
#lorem(100)
#pagebreak()