From ae6405c28837ae8261c28118cdf2844d2b6c97a1 Mon Sep 17 00:00:00 2001 From: Thijs Paelman Date: Tue, 27 May 2025 13:30:23 +0200 Subject: [PATCH] feat(glossy): Check validity of modifiers When an unrecognized modifier is applied, glossy should panic to warn the user, instead of silently ignoring the modifier. This might catch potential misspellings of modifiers. --- glossy/README.md | 2 ++ glossy/src/gloss.typ | 11 ++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/glossy/README.md b/glossy/README.md index 8f9e870..ba3e7f8 100644 --- a/glossy/README.md +++ b/glossy/README.md @@ -411,3 +411,5 @@ This project is licensed under the MIT License. now counts towards the first use of a term. - **Breaking**: When multiple conflicting modes are supplied (like 'short' and 'long'), glossy now throws an error (with a clear message). +- **Breaking**: When an unrecognized modifier is supplied with the term, + glossy will now panic instead of ignoring the modifier. diff --git a/glossy/src/gloss.typ b/glossy/src/gloss.typ index c034f7a..923838c 100644 --- a/glossy/src/gloss.typ +++ b/glossy/src/gloss.typ @@ -227,7 +227,7 @@ #let __gls(key, modes-modifiers: array, format-term: function, show-term: function, term-links: true, display-text: none) = { let possible_modes = ("auto", "both", "short", "long", "description", "supplement") // --------------------------------------------------------------------------- - // Normalize mode & modifier inputs AND first sanitization + // Normalize mode & modifier inputs AND check if the modifiers are valid // --------------------------------------------------------------------------- let modes-modifiers = modes-modifiers.map(it => { if it == "def" or it == "desc" { @@ -240,11 +240,12 @@ return "no-use" } else if it == "noref" or it == "noindex" { return "noindex" - } else if it in ("auto", "supplement", "__MIDDLE_ITEM") { - // Already internally used, don't make user input confuse us - panic(it, "should not be used as a modifier") - } else { + } else if it in ("both", "short", "long", "cap", "pl",) { return it + } else if it in ("auto", "description", "supplement") { + panic(it, "is a valid mode, but is not used by applying a modifier with this name. Read the documentation.") + } else { + panic(it, "is not a recognized mode or modifier.") } }) if display-text != none and display-text != auto {