From ce94168b13a05239ff4d75f5957cf23ce1c3e256 Mon Sep 17 00:00:00 2001 From: servostar Date: Fri, 19 Jul 2024 15:08:11 +0200 Subject: [PATCH] added prettier code blocks --- src/conf.typ | 2 ++ src/style.typ | 54 ++++++++++++++++++++++++++++++++++++++++++++++- template/main.typ | 34 ++++++----------------------- 3 files changed, 61 insertions(+), 29 deletions(-) diff --git a/src/conf.typ b/src/conf.typ index cfc76ed..c4a7e51 100644 --- a/src/conf.typ +++ b/src/conf.typ @@ -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))) diff --git a/src/style.typ b/src/style.typ index d7365a6..c9ddabe 100644 --- a/src/style.typ +++ b/src/style.typ @@ -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) diff --git a/template/main.typ b/template/main.typ index 1b7c40a..fb9344d 100644 --- a/template/main.typ +++ b/template/main.typ @@ -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() -- 2.40.1