-
Notifications
You must be signed in to change notification settings - Fork 116
Add support for blockquote alerts in layout files #3073
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{{ $emojis := dict | ||
"caution" ":bangbang:" | ||
"important" ":information_source:" | ||
"note" ":memo:" | ||
"tip" ":bulb:" | ||
"warning" ":warning:" | ||
}} | ||
|
||
{{ $type := .type | default "note" }} | ||
{{ $title := .title | default "" }} | ||
{{ $content := .content | default "" }} | ||
{{ $html := .html | default "" }} | ||
Comment on lines
+9
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This got a bit more complex than I intended. I was looking for a way to pass the alert string in layout files without having to write so many HTML tags as in this example (while ensuring Markdown and HTML still got parsed correctly whether coming from the partial or shortcode): (sample conversion from
I ended up creating two separate content parameters for the partial. |
||
|
||
{{/* Handle inner content from shortcodes */}} | ||
{{ if .inner }} | ||
{{ $content = .inner }} | ||
{{ end }} | ||
|
||
{{ if $type }} | ||
<blockquote class="alert alert-{{ $type }}"> | ||
<p class="alert-heading"> | ||
{{ transform.Emojify (index $emojis $type) }} | ||
{{ if $title }} | ||
{{ $title }} | ||
{{ else }} | ||
{{ or (i18n $type) (title $type) }} | ||
{{ end }} | ||
</p> | ||
<div class="alert-content"> | ||
{{ if $html }} | ||
{{ $html | safeHTML }} | ||
{{ else if $content }} | ||
{{ $content | markdownify }} | ||
{{ else }} | ||
{{ i18n "no-content" }} | ||
{{ end }} | ||
</div> | ||
</blockquote> | ||
{{ else }} | ||
<blockquote> | ||
{{ $content | markdownify }} | ||
</blockquote> | ||
{{ end }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{{ $type := .Get "type" | default "note" }} | ||
{{ $title := .Get "title" | default "" }} | ||
{{ $inner := .Inner }} | ||
|
||
{{ partial "blockquote-alert" (dict | ||
"type" $type | ||
"title" $title | ||
"inner" $inner | ||
) }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I haven't deleted the render hook. So, it's still possible to use the old syntax. Please confirm that I can remove it. Or let me know if you'd like to keep it.