Skip to content

Commit

Permalink
💄 style: fix numbered code blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
welpo committed Nov 23, 2024
1 parent cf63855 commit dd53ba2
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 6 deletions.
38 changes: 37 additions & 1 deletion content/blog/markdown/index.ca.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
+++
title = "Exemples de Markdown"
date = 2023-01-31
updated = 2023-09-01
updated = 2024-11-23
description = "Aquesta publicació mostra alguns exemples de format en Markdown, incloent-hi una taula, blocs de codi i etiquetes, citacions, taules i notes a peu de pàgina."

[taxonomies]
Expand Down Expand Up @@ -59,6 +59,42 @@ fn main() {
}
```

### Amb numeració de línies

```rust,linenos
use std::collections::HashMap;
#[derive(Debug)]
struct TwinPeaksCharacter {
name: String,
coffee_rating: f32,
pie_preference: String,
}
fn main() {
let mut black_lodge = HashMap::new();
black_lodge.insert("agent", TwinPeaksCharacter {
name: String::from("Dale Cooper"),
coffee_rating: 9999.99,
pie_preference: String::from("Damn Fine Cherry"),
});
black_lodge.insert("giant", TwinPeaksCharacter {
name: String::from("The Fireman"),
coffee_rating: 42.424242,
pie_preference: String::from("Garmonbozia"),
});
// Calculate total appreciation of damn fine coffee
let total_coffee: f32 = black_lodge.values()
.map(|character| character.coffee_rating)
.sum();
println!("☕ Total coffee appreciation: {:.2} cups", total_coffee);
}
```

## Etiquetes de codi

A Rust, declares una variable mutable amb `let mut x = 5;`, mentre que a Python, simplement fas `x = 5`. De manera similar, per imprimir un valor a Rust, utilitzaries `println!("Valor: {}", x);`, però a Python, és tan senzill com `print(f"Valor: {x}")`.
Expand Down
38 changes: 37 additions & 1 deletion content/blog/markdown/index.es.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
+++
title = "Ejemplos de Markdown"
date = 2023-01-31
updated = 2023-09-01
updated = 2024-11-23
description = "Esta publicación muestra algunos ejemplos de formato Markdown, incluyendo una tabla, bloques de código y etiquetas, citas, tablas y notas al pie de página."

[taxonomies]
Expand Down Expand Up @@ -59,6 +59,42 @@ fn main() {
}
```

### Con números de línea

```rust,linenos
use std::collections::HashMap;
#[derive(Debug)]
struct TwinPeaksCharacter {
name: String,
coffee_rating: f32,
pie_preference: String,
}
fn main() {
let mut black_lodge = HashMap::new();
black_lodge.insert("agent", TwinPeaksCharacter {
name: String::from("Dale Cooper"),
coffee_rating: 9999.99,
pie_preference: String::from("Damn Fine Cherry"),
});
black_lodge.insert("giant", TwinPeaksCharacter {
name: String::from("The Fireman"),
coffee_rating: 42.424242,
pie_preference: String::from("Garmonbozia"),
});
// Calculate total appreciation of damn fine coffee
let total_coffee: f32 = black_lodge.values()
.map(|character| character.coffee_rating)
.sum();
println!("☕ Total coffee appreciation: {:.2} cups", total_coffee);
}
```

## Etiquetas de código

En Rust, declaras una variable mutable con `let mut x = 5;`, mientras que en Python, simplemente usas `x = 5`. De manera similar, para imprimir un valor en Rust, utilizarías `println!("Valor: {}", x);`, pero en Python, es tan sencillo como `print(f"Valor: {x}")`.
Expand Down
38 changes: 37 additions & 1 deletion content/blog/markdown/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
+++
title = "Markdown examples"
date = 2023-01-31
updated = 2023-09-01
updated = 2024-11-23
description = "This post showcases some examples of Markdown formatting, including a table, code blocks and tags, quotes, tables, and footnotes."

[taxonomies]
Expand Down Expand Up @@ -59,6 +59,42 @@ fn main() {
}
```

### With line numbers

```rust,linenos
use std::collections::HashMap;
#[derive(Debug)]
struct TwinPeaksCharacter {
name: String,
coffee_rating: f32,
pie_preference: String,
}
fn main() {
let mut black_lodge = HashMap::new();
black_lodge.insert("agent", TwinPeaksCharacter {
name: String::from("Dale Cooper"),
coffee_rating: 9999.99,
pie_preference: String::from("Damn Fine Cherry"),
});
black_lodge.insert("giant", TwinPeaksCharacter {
name: String::from("The Fireman"),
coffee_rating: 42.424242,
pie_preference: String::from("Garmonbozia"),
});
// Calculate total appreciation of damn fine coffee
let total_coffee: f32 = black_lodge.values()
.map(|character| character.coffee_rating)
.sum();
println!("☕ Total coffee appreciation: {:.2} cups", total_coffee);
}
```

## Code tags

In Rust, you declare a mutable variable with `let mut x = 5;`, whereas in Python, you simply use `x = 5`. Similarly, to print a value in Rust, you would use `println!("Value: {}", x);`, but in Python, it's as straightforward as `print(f"Value: {x}")`.
Expand Down
13 changes: 10 additions & 3 deletions sass/parts/_code.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ code {
padding: 0rem;
}

// Line number col.
tbody td:first-child {
width: 2rem;
opacity: 50%;
padding-inline-end: 0.8rem;
width: 0rem;
user-select: none;
text-align: start;
text-align: end;
}

tbody tr:nth-child(even) {
Expand All @@ -54,6 +57,11 @@ pre {
overflow-x: auto;
line-height: 1.4;

code,
code td {
font-size: 0.8rem; // Fits ~77 characters.
}

code {
display: block;
border: 0rem;
Expand All @@ -62,7 +70,6 @@ pre {
padding: 0rem;
overflow-x: auto;
color: inherit;
font-size: 0.8rem; // Fits ~77 characters.
white-space: pre;

&::before {
Expand Down

0 comments on commit dd53ba2

Please sign in to comment.