From c191d6efd94447ba39710df8d25504c4105aac47 Mon Sep 17 00:00:00 2001 From: Wesley Moore Date: Tue, 20 Feb 2024 20:46:22 +1000 Subject: [PATCH] Add Gleam syntax highlighting --- .gitmodules | 3 ++ v2/config.toml | 1 + v2/content/posts/2024/gleam-tauri/index.md | 42 ++++++++++++++++++++-- v2/syntaxes/gleam | 1 + 4 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 .gitmodules create mode 160000 v2/syntaxes/gleam diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..561a9ae --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "v2/syntaxes/gleam"] + path = v2/syntaxes/gleam + url = https://github.com/digitalcora/sublime-text-gleam.git diff --git a/v2/config.toml b/v2/config.toml index 4328bf7..65134c9 100644 --- a/v2/config.toml +++ b/v2/config.toml @@ -19,6 +19,7 @@ build_search_index = false # Theme can be customised by setting the `highlight_theme` variable to a theme supported by Zola highlight_code = true smart_punctuation = true +extra_syntaxes_and_themes = ["syntaxes/gleam"] [extra] author = "Wesley Moore" diff --git a/v2/content/posts/2024/gleam-tauri/index.md b/v2/content/posts/2024/gleam-tauri/index.md index 8f7d604..a97dc82 100644 --- a/v2/content/posts/2024/gleam-tauri/index.md +++ b/v2/content/posts/2024/gleam-tauri/index.md @@ -35,10 +35,46 @@ maintained Elm without the restrictions on interop with existing JavaScript code. To get started here's some Gleam code that demonstrates a decent chunk of the -language. My blog doesn't highlight Gleam code at the moment so what's shown -below is a picture. See [example.gleam](example.gleam) for the source file: +language: - +```gleam +import gleam/io +import gleam/list +import gleam/int + +pub type Temperature { + F(Float) + C(Float) +} + +pub type Celcius { + Celcius(Float) +} + +pub fn main() { + let temps = [C(22.0), C(-5.0), F(0.0), C(0.0), F(32.0)] + io.debug(avg(temps)) +} + +pub fn avg(measurements: List(Temperature)) -> Celcius { + let sum = + list.fold(measurements, 0.0, fn(sum, val) { + let Celcius(c) = to_c(val) + sum +. c + }) + let length = + list.length(measurements) + |> int.to_float + Celcius(sum /. length) +} + +fn to_c(temp: Temperature) -> Celcius { + case temp { + C(c) -> Celcius(c) + F(f) -> Celcius({ f -. 32.0 } /. 1.8) + } +} +``` When run it outputs: diff --git a/v2/syntaxes/gleam b/v2/syntaxes/gleam new file mode 160000 index 0000000..6c2080b --- /dev/null +++ b/v2/syntaxes/gleam @@ -0,0 +1 @@ +Subproject commit 6c2080bf6039aa4c844086953d5aca49a7cd5ab6