linking with custom text

This commit is contained in:
Tove 2025-09-15 12:33:25 +02:00
parent 93ecf7bb49
commit 0fff91298d
Signed by: TudbuT
GPG key ID: B3CF345217F202D3
2 changed files with 9 additions and 2 deletions

View file

@ -26,7 +26,8 @@ binary at target/release/itemse2.
- Items and locations can be temporarily taken out of storage, which puts
them in "limbo"
- Linking to other things in descriptions: `[%type%:%id%]`, e.g.
`[location:019830dd-3b1b-7543-8fb9-8ccfdb1c6456]`
`[location:019830dd-3b1b-7543-8fb9-8ccfdb1c6456]` (append an additional
`:` followed by any text to customize the displayed link text)
## Usage

View file

@ -1093,9 +1093,15 @@ fn description(inp: &str) -> String {
static RE_LINK: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(r"\[(item|location|itemtype|note):([0-9a-fA-F\-]+)\]").unwrap()
});
static RE_LINK_CUSTOM: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(r"\[(item|location|itemtype|note):([0-9a-fA-F\-]+):([^]]+)\]").unwrap()
});
RE_LINK
.replace_all(
&inp.replace("<", "&lt;").replace(">", "&gt;"),
&RE_LINK_CUSTOM.replace_all(
&inp.replace("<", "&lt;").replace(">", "&gt;"),
"<a href=/$1/$2>[$3]</a>",
),
"<a href=/$1/$2>[$1]</a>",
)
.to_string()