Compare commits

..

2 Commits

Author SHA1 Message Date
Sven Vogel 4e82edce06 Merge pull request 'added prettier code blocks' (#36) from feature/pretty-codeblocks into main
Gitea Action for checking typst compilation / run-ci-linux (push) Successful in 30s Details
release / release (push) Successful in 1m7s Details
Reviewed-on: #36
2024-07-19 13:09:01 +00:00
Sven Vogel ce94168b13 added prettier code blocks
Gitea Action for checking typst compilation / run-ci-linux (push) Successful in 27s Details
2024-07-19 15:08:11 +02:00
3 changed files with 61 additions and 29 deletions

View File

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

View File

@ -78,7 +78,59 @@
set raw( set raw(
tab-size: style.code.tab-size, tab-size: style.code.tab-size,
theme: style.code.theme) 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) show figure: set block(breakable: true)

View File

@ -5,6 +5,7 @@
#show: dhbw-template.with(( #show: dhbw-template.with((
lang: "en", lang: "en",
region: "en", region: "en",
draft: false,
author: ( author: (
name: "Sven Vogel", name: "Sven Vogel",
semester: 4, semester: 4,
@ -80,6 +81,8 @@ $
#pagebreak() #pagebreak()
#lorem(100)
#figure( #figure(
```rust ```rust
use std::env; use std::env;
@ -87,37 +90,12 @@ use std::fs::OpenOptions;
use std::io::Write; use std::io::Write;
fn main() { fn main() {
// Get the file path from the environment variable println!("Hello, World!!!");
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);
}
} }
```, caption: [Some code]) ```, caption: [Some code])
#lorem(100)
#pagebreak() #pagebreak()