Link styling tweaks

This commit is contained in:
Nathan McCarty 2025-02-09 17:10:46 -05:00
parent 5ad9ff656f
commit 972b73f665
3 changed files with 31 additions and 11 deletions

View file

@ -47,7 +47,6 @@ sub site-header(BlogMeta:D $meta) is export {
sub header-link($name, $path, $icon) { sub header-link($name, $path, $icon) {
a :href("$path"), [ a :href("$path"), [
icon $icon; icon $icon;
' ';
span $name; span $name;
] ]
} }

View file

@ -10,7 +10,8 @@ sub show-html($html) is export {
# Work around HTML::Functional automatically putting newlines between tags # Work around HTML::Functional automatically putting newlines between tags
$out ~~ s:g/'</i>' \v+ '<span>'/<\/i><span>/; $out ~~ s:g/'</i>' \v+ '<span>'/<\/i><span>/;
$out ~~ s:g/\v+ '</a>'/<\/a>/; $out ~~ s:g/\v+ '</a>'/<\/a>/;
$out ~~ s:g/',' \v+ '<span'/,<span/; $out ~~ s:g/\s+ ',' \s+ '<span'/, <span/;
# TODO: Deal with the nbsps in the header
$out $out
} }

View file

@ -11,18 +11,19 @@ unsafe variadics, and dynamic languages, like python, can do the same while
being memory safe by not being type safe, many type safe languages, such as being memory safe by not being type safe, many type safe languages, such as
Rust, are forced to provide such functionality through the use of a macro. Rust, are forced to provide such functionality through the use of a macro.
Dependently typed languages, like Idris, can provide a printf like formatting Dependently typed languages, like Idris, can provide a printf like formatting
interface, while maintaining both memory and type saftey, without the need for interface, while maintaining both memory and type safety, without the need for
the macro. We will explore this by implementing a simplified version of `printf` the macro. We will explore this by implementing a simplified version of `printf`
in Idris from scratch. in Idris from scratch.
This article is inspired by an exercise from chapter 6 of [Type Driven This article is inspired by an exercise from chapter 6 of
Development with [Type Driven Development with Idris](https://www.manning.com/books/type-driven-development-with-idris),
Idris](https://www.manning.com/books/type-driven-development-with-idris), and is and is written as a literate Idris file, with the source available
written as a literate Idris file. [here](https://git.stranger.systems/thatonelutenist/website/src/branch/trunk/projects/Idris/src/LessMacrosMoreTypes/Printf.md).
## Gameplan ## Gameplan
Our goal is to provide a printf function that can be called, much like it's C equivlant, like so: Our goal is to provide a printf function that can be called, much like it's C
equivalent:
> [!NOTE] > [!NOTE]
> As this is a literate Idris document, and we haven't defined our `printf` > As this is a literate Idris document, and we haven't defined our `printf`
@ -33,13 +34,32 @@ Our goal is to provide a printf function that can be called, much like it's C eq
```idris ```idris
failing failing
example_usage : String example_usage : String
example_usage = printf "%s %d %02d" "hello" 1 2 example_usage = printf "%s %d %2d" "hello" 1 2
``` ```
## Parsing a Format String ## Parsing a Format String
First, we need a data structure to describe our format string. We define the
`Format` data type, with constructors for each of the format specifiers we will
be supporting, as well as a constructor to hold literal components.
```idris
data Format : Type where
||| A slot that should be filled in with a number
Number : (next : Format) -> Format
||| A slot that should be filled in with a number, padded to a certian number
||| of digits
PaddedNumber : (digits : Nat) -> Format
||| A slot that should be filled in with a string
Str : (next : Format) -> Format
||| A literal component of the format string that should not be interpolated
Literal : (literal : String) -> (next : Format) -> Format
||| The end of the format string
End : Format
```
## Calculating a Type From a Format String ## Calculating a Type From a Format String
## printf ## printf
## Working with run-time format strings