From 8798f5b51f87e6a1cdba9ab9636392918662bf73 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Thu, 29 Aug 2024 17:57:22 +0800 Subject: [PATCH] :tada: Feat: add blockquote render hook to support GitHub alerts markdown syntax simpler callouts or admonitions sytax --- assets/images/icons/alerts/alert.svg | 1 + assets/images/icons/alerts/info.svg | 1 + assets/images/icons/alerts/light-bulb.svg | 1 + assets/images/icons/alerts/report.svg | 1 + assets/images/icons/alerts/stop.svg | 1 + .../_default/_markup/render-blockquote.html | 33 +++++++++++++++++++ 6 files changed, 38 insertions(+) create mode 100644 assets/images/icons/alerts/alert.svg create mode 100644 assets/images/icons/alerts/info.svg create mode 100644 assets/images/icons/alerts/light-bulb.svg create mode 100644 assets/images/icons/alerts/report.svg create mode 100644 assets/images/icons/alerts/stop.svg create mode 100644 layouts/_default/_markup/render-blockquote.html diff --git a/assets/images/icons/alerts/alert.svg b/assets/images/icons/alerts/alert.svg new file mode 100644 index 00000000..320217da --- /dev/null +++ b/assets/images/icons/alerts/alert.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/images/icons/alerts/info.svg b/assets/images/icons/alerts/info.svg new file mode 100644 index 00000000..ba409a68 --- /dev/null +++ b/assets/images/icons/alerts/info.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/images/icons/alerts/light-bulb.svg b/assets/images/icons/alerts/light-bulb.svg new file mode 100644 index 00000000..61ce7906 --- /dev/null +++ b/assets/images/icons/alerts/light-bulb.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/images/icons/alerts/report.svg b/assets/images/icons/alerts/report.svg new file mode 100644 index 00000000..66a48dd5 --- /dev/null +++ b/assets/images/icons/alerts/report.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/images/icons/alerts/stop.svg b/assets/images/icons/alerts/stop.svg new file mode 100644 index 00000000..670147ea --- /dev/null +++ b/assets/images/icons/alerts/stop.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/layouts/_default/_markup/render-blockquote.html b/layouts/_default/_markup/render-blockquote.html new file mode 100644 index 00000000..c8bfdd73 --- /dev/null +++ b/layouts/_default/_markup/render-blockquote.html @@ -0,0 +1,33 @@ +{{- $icons := dict + "caution" "images/icons/alerts/stop.svg" + "important" "images/icons/alerts/report.svg" + "note" "images/icons/alerts/info.svg" + "tip" "images/icons/alerts/light-bulb.svg" + "warning" "images/icons/alerts/alert.svg" +-}} + +{{- $Attrs := "" }} +{{- range $key, $value := .Attributes }} + {{- if $value }} + {{- $Attrs = printf "%s %s=%q" $Attrs $key $value }} + {{- end }} +{{- end }} +{{- $Attrs = trim $Attrs " " }} + +{{- if eq .Type "alert" -}} + {{- with .Attributes.class }} + {{- $Attrs = trim (replace $Attrs . (printf "alert alert-%s %s" $.AlertType .)) " " }} + {{- else }} + {{- $Attrs = trim (printf "class=%q %s" (printf "alert alert-%s" $.AlertType) $Attrs) " " }} + {{- end -}} +
+ {{- $icon := index $icons .AlertType -}} +

+ {{- dict "Src" $icon | partial "plugin/icon.html" }} + {{- or (T .AlertType) (title .AlertType) -}} +

+ {{- .Text | safeHTML -}} +
+{{- else -}} +
{{ .Text | safeHTML }}
+{{- end -}}