From c257b9b10fbf22d6738ae0fa2a3d57f5525843eb Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Thu, 8 Jan 2026 16:13:09 +0800 Subject: [PATCH] feat(admonition): add support for content-only alerts without titles (#683) * feat(admonition): add support for content-only alerts without titles * fix(admonition): improve title-only alert handling and styling --- .../posts/alert-and-admonition-test.md | 7 +++- assets/css/_shortcodes/_admonition.scss | 33 ++++++++++++------- layouts/_partials/plugin/admonition.html | 27 ++++++++------- 3 files changed, 44 insertions(+), 23 deletions(-) diff --git a/apps/test/content/posts/alert-and-admonition-test.md b/apps/test/content/posts/alert-and-admonition-test.md index b2884031..1e8a8f68 100644 --- a/apps/test/content/posts/alert-and-admonition-test.md +++ b/apps/test/content/posts/alert-and-admonition-test.md @@ -39,7 +39,7 @@ This article comprehensively tests the **Alerts** Markdown syntax extension and > [!NOTE] FixIt > A clean, elegant but advanced Hugo theme. -> [!TIP] This is a title-only alert +> [!TIP] This is a title-only alert. ### Foldable Alerts @@ -59,6 +59,11 @@ Alerts can be nested in multiple levels: > > [!todo] Yes! They can be nested. > > > [!example] You can even use multiple layers of nesting. +### Content-only Alerts + +> [!TIP]~ +> This is a content-only alert without a title. + ### Supported types > [!note]+ diff --git a/assets/css/_shortcodes/_admonition.scss b/assets/css/_shortcodes/_admonition.scss index b50115ea..d04b427a 100644 --- a/assets/css/_shortcodes/_admonition.scss +++ b/assets/css/_shortcodes/_admonition.scss @@ -7,10 +7,11 @@ @include border-radius($global-border-radius); .admonition-title { - font-weight: var(--admonition-title-font-weight, bold); + font-weight: var(#{$rootPrefix}admonition-title-font-weight, bold); margin: 0 -0.75rem; padding: 0.25rem 1.8rem; border-bottom: 1px solid; + position: relative; @include border-radius(0); strong { @@ -22,8 +23,11 @@ } } - &:has(+ .details-content > .admonition-content:empty) { - --admonition-title-font-weight: normal; + // title-only admonition without content + &:not(:has(+ .details-content)) { + #{$rootPrefix}admonition-title-font-weight: normal; + padding: 0.75rem 1rem 0.75rem 1.8rem; + border: 0; } } @@ -34,10 +38,6 @@ > p { margin: 0; } - // title-only alert - &:empty { - display: none; - } .code-block .code-header { top: initial !important; @@ -47,14 +47,16 @@ i.icon { font-size: 0.85rem; position: absolute; - top: 0.6rem; - left: 0.4rem; + top: 50%; + left: 0.9rem; + translate: -50% -50%; } i.details-icon { position: absolute; - top: 0.6rem; - right: 0.3rem; + top: 50%; + right: 0.9rem; + translate: 50% -50%; } background-color: var(#{$rootPrefix}admonition-bg-color); @@ -92,4 +94,13 @@ &:last-child { margin-bottom: 0.75rem; } + + // content-only admonition without title + &:not(:has(.admonition-title)) { + border-left: 0; + + .admonition-content { + padding: 0.75rem 0.25rem; + } + } } diff --git a/layouts/_partials/plugin/admonition.html b/layouts/_partials/plugin/admonition.html index 5e4024dc..00a8db60 100644 --- a/layouts/_partials/plugin/admonition.html +++ b/layouts/_partials/plugin/admonition.html @@ -46,20 +46,25 @@ {{- $type = index $aliasMap $type | default $type | default "note" -}} {{- $icon := index $iconMap $type | default "fa-solid fa-pencil-alt" -}} {{- $title := .Title | default (T (printf "admonition.%v" $type)) | default (title $type) -}} +{{- $titleless := eq .Title "~" -}} {{- $foldable := ne .Foldable false -}}
-
- {{- dict "Class" (add "icon fa-fw " $icon) | partial "plugin/icon.html" -}} - {{- $title | safeHTML -}} - {{- if $foldable -}} - {{- dict "Class" "details-icon fa-solid fa-angle-right fa-fw" | partial "plugin/icon.html" -}} - {{- end -}} -
-
-
- {{- .Text | safeHTML -}} + {{- if not $titleless }} +
+ {{- dict "Class" (add "icon fa-fw " $icon) | partial "plugin/icon.html" -}} + {{- $title | safeHTML -}} + {{- if $foldable -}} + {{- dict "Class" "details-icon fa-solid fa-angle-right fa-fw" | partial "plugin/icon.html" -}} + {{- end -}}
-
+ {{- end }} + {{- with .Text -}} +
+
+ {{- . | safeHTML -}} +
+
+ {{- end }}
{{- /* EOF */ -}}