From c062fd1ed2a28faac56d4693a8f6e236345f9706 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Mon, 24 Mar 2025 12:16:10 +0100 Subject: [PATCH] tree: use style color if name conflict #1067 --- docs/content/shortcodes/tree.en.md | 8 ++++---- layouts/partials/shortcodes/tree.html | 28 +++++++++++++++++++++++++-- layouts/partials/version.txt | 2 +- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/docs/content/shortcodes/tree.en.md b/docs/content/shortcodes/tree.en.md index 556c64d49c..3e8dac388a 100644 --- a/docs/content/shortcodes/tree.en.md +++ b/docs/content/shortcodes/tree.en.md @@ -79,9 +79,9 @@ The **NAME** can be followed by optional double colons (`::`) to define an **ICO - by brand color: `primary`, `secondary`, `accent` - by color: `blue`, `cyan`, `green`, `grey`, `magenta`, `orange`, `red` - by special color: `default`, `transparent`, `code` - - you can also [define your own styles](#defining-own-styles). + - you can also [define your own styles](shortcodes/notice#defining-own-styles). - If a **style** and a named HTML color have the same name, the HTML color will be used. + If a **style** and a named HTML color have the same name, the **style** color will be used. ## Examples @@ -106,7 +106,7 @@ Every possible combination - and now with color::fa-fw fab fa-php - script.php::fa-fw fab fa-markdown::purple - alt script.php::fa-fw fab fa-markdown::#888cc4 - - magic.php::fa-fw fab fa-markdown::magic + - magic.php::fa-fw fab fa-markdown::orange ``` ```` @@ -126,5 +126,5 @@ Every possible combination - and now with color::fa-fw fab fa-php - script.php::fa-fw fab fa-php::purple - alt script.php::fa-fw fab fa-php::#888cc4 - - magic.php::fa-fw fab fa-php::magic + - magic.php::fa-fw fab fa-php::orange ```` diff --git a/layouts/partials/shortcodes/tree.html b/layouts/partials/shortcodes/tree.html index 66fa326538..7570747d71 100644 --- a/layouts/partials/shortcodes/tree.html +++ b/layouts/partials/shortcodes/tree.html @@ -1,7 +1,31 @@ {{ $content := .content | .page.RenderString }}
-{{- $content = (replaceRE `
  • ([^<>:]+)::([\w-]+)::([^<>\n\r\t ]+)` `
  • $1` $content) }} -{{- $content = (replaceRE `
  • ([^<>:]+)::([^<>:]+)::([^<>\n\r\t ]+)` `
  • $1` $content) }} +{{- $matches := findRESubmatch `
  • ([^<>:]+)::([\w-]+)::([^<>\n\r\t ]+)` $content }} +{{- range $matches }} + {{- $name := index . 1 }} + {{- $icon := index . 2 }} + {{- $color := index . 3 }} + {{- $replacement := "" }} + {{- if (where site.Params.boxStyle "identifier" $color | first 1) }} + {{- $replacement = printf `
  • %s` $icon $color $name }} + {{- else }} + {{- $replacement = printf `
  • %s` $icon $color $name }} + {{- end }} + {{- $content = replace $content (index . 0) $replacement }} +{{- end }} +{{- $matches := findRESubmatch `
  • ([^<>:]+)::([^<>:]+)::([^<>\n\r\t ]+)` $content }} +{{- range $matches }} + {{- $name := index . 1 }} + {{- $icon := index . 2 }} + {{- $color := index . 3 }} + {{- $replacement := "" }} + {{- if (where site.Params.boxStyle "identifier" $color | first 1) }} + {{- $replacement = printf `
  • %s` $icon $color $name }} + {{- else }} + {{- $replacement = printf `
  • %s` $icon $color $name }} + {{- end }} + {{- $content = replace $content (index . 0) $replacement }} +{{- end }} {{- $content = (replaceRE `
  • ([^<>:]+)::([\w-]+)([\n\r\t ]*<)` `
  • $1$3` $content) }} {{- $content = (replaceRE `
  • ([^<>:]+)::([^<>\n\r\t]+)` `
  • $1` $content) }} {{- $content | safeHTML -}} diff --git a/layouts/partials/version.txt b/layouts/partials/version.txt index bd15d9fcb3..601cf8f3b1 100644 --- a/layouts/partials/version.txt +++ b/layouts/partials/version.txt @@ -1 +1 @@ -7.5.0+0d71747e13e0d9d91321f28327447ea0b4310bcc \ No newline at end of file +7.5.0+964ca24fd04abba3d8c22dd7bdc9de5a707e08fe \ No newline at end of file