Skip to content

Instantly share code, notes, and snippets.

@RemiBardon
Last active January 5, 2024 02:03
Show Gist options
  • Select an option

  • Save RemiBardon/0156d028e83137011ac38b22d3fbef26 to your computer and use it in GitHub Desktop.

Select an option

Save RemiBardon/0156d028e83137011ac38b22d3fbef26 to your computer and use it in GitHub Desktop.
Obsidian-style callouts in Hugo
:root {
--color-red-rgb: 233, 49, 71;
--color-orange-rgb: 236, 117, 0;
--color-yellow-rgb: 224, 172, 0;
--color-green-rgb: 8, 185, 78;
--color-cyan-rgb: 0, 191, 188;
--color-blue-rgb: 8, 109, 221;
--color-purple-rgb: 120, 82, 238;
--color-pink-rgb: 213, 57, 132;
}
.dark {
--color-red-rgb: 251, 70, 76;
--color-orange-rgb: 233, 151, 63;
--color-yellow-rgb: 224, 222, 113;
--color-green-rgb: 68, 207, 110;
--color-cyan-rgb: 83, 223, 221;
--color-blue-rgb: 2, 122, 255;
--color-purple-rgb: 168, 130, 255;
--color-pink-rgb: 250, 153, 205;
}
body {
--callout-color-bug-rgb: var(--color-red-rgb);
--callout-color-error-rgb: var(--color-red-rgb);
--callout-color-example-rgb: var(--color-purple-rgb);
--callout-color-fail-rgb: var(--color-red-rgb);
--callout-color-important-rgb: var(--color-cyan-rgb);
--callout-color-info-rgb: var(--color-blue-rgb);
--callout-color-question-rgb: var(--color-orange-rgb);
--callout-color-success-rgb: var(--color-green-rgb);
--callout-color-summary-rgb: var(--color-cyan-rgb);
--callout-color-tip-rgb: var(--color-cyan-rgb);
--callout-color-todo-rgb: var(--color-blue-rgb);
--callout-color-warning-rgb: var(--color-orange-rgb);
--callout-color-quote-rgb: 158, 158, 158;
}
.callout {
margin: 1em 0;
padding: 0.75em 0.75em 0.75em 1.5em;
overflow: hidden;
background-color: rgba(var(--callout-color-rgb), 0.1);
border-radius: .25rem;
}
.callout p {
margin-top: 0.5em;
margin-bottom: 0.5em;
}
.callout:not([disabled]) > summary {
cursor: pointer;
}
.callout > summary > * {
display: inline;
}
.callout > summary {
list-style: none;
padding: 0;
display: flex;
gap: .4rem;
color: rgb(var(--callout-color-rgb));
line-height: 1.3;
align-items: flex-start;
}
.callout[open] > summary:not(:last-child) {
margin-bottom: 12px;
}
.callout > summary {
transition: margin-bottom 100ms ease-in-out;
}
.callout[open] > summary .chevron {
transform: rotate(90deg);
}
.callout > summary .chevron {
transition: transform 100ms ease-in-out;
}
.callout[disabled] > summary {
pointer-events: none;
}
.callout[disabled] > summary a {
pointer-events: initial;
}
.callout[disabled] > summary .chevron {
display: none;
}
.callout[data-callout="abstract"],
.callout[data-callout="summary"],
.callout[data-callout="tldr"] {
--callout-color-rgb: var(--callout-color-summary-rgb);
}
.callout[data-callout="note"],
.callout[data-callout="info"] {
--callout-color-rgb: var(--callout-color-info-rgb);
}
.callout[data-callout="todo"] {
--callout-color-rgb: var(--callout-color-todo-rgb);
}
.callout[data-callout="important"] {
--callout-color-rgb: var(--callout-color-important-rgb);
}
.callout[data-callout="tip"],
.callout[data-callout="hint"] {
--callout-color-rgb: var(--callout-color-tip-rgb);
}
.callout[data-callout="success"],
.callout[data-callout="check"],
.callout[data-callout="done"] {
--callout-color-rgb: var(--callout-color-success-rgb);
}
.callout[data-callout="question"],
.callout[data-callout="help"],
.callout[data-callout="faq"] {
--callout-color-rgb: var(--callout-color-question-rgb);
}
.callout[data-callout="warning"],
.callout[data-callout="caution"],
.callout[data-callout="attention"] {
--callout-color-rgb: var(--callout-color-warning-rgb);
}
.callout[data-callout="failure"],
.callout[data-callout="fail"],
.callout[data-callout="missing"] {
--callout-color-rgb: var(--callout-color-fail-rgb);
}
.callout[data-callout="danger"],
.callout[data-callout="error"] {
--callout-color-rgb: var(--callout-color-error-rgb);
}
.callout[data-callout="bug"] {
--callout-color-rgb: var(--callout-color-bug-rgb);
}
.callout[data-callout="example"] {
--callout-color-rgb: var(--callout-color-example-rgb);
}
.callout[data-callout="quote"],
.callout[data-callout="cite"] {
--callout-color-rgb: var(--callout-color-quote-rgb);
}
{{- $type := "" }}
{{- if .IsNamedParams }}
{{- with .Get "type" }}
{{- $type = . }}
{{- else }}
{{- errorf "'type' param required: %s" $.Position }}
{{- end }}
{{- else }}
{{- with .Get 0 }}
{{- $type = . }}
{{- else }}
{{- errorf "At least one param should be provided: 'type': %s" $.Position }}
{{- end }}
{{- end }}
{{- $icon := partialCached "callout-icon.html" $type $type }}
{{- $fold := "" }}
{{- if .IsNamedParams }}
{{- with .Get "fold" }}
{{ $fold = . }}
{{- end }}
{{- else }}
{{- with .Get 1 }}
{{ $fold = . }}
{{- end }}
{{- end }}
{{- $summary := "" }}
{{- if .IsNamedParams }}
{{- with .Get "title" }}
{{ $summary = . }}
{{- else }}
{{- $summary = (partialCached "callout-default-summary.txt" $type $type site.Language.LanguageCode) }}
{{- end }}
{{- else }}
{{- with .Get 2 }}
{{ $summary = . }}
{{- else }}
{{- $summary = (partialCached "callout-default-summary.txt" $type $type site.Language.LanguageCode) }}
{{- end }}
{{- end }}
<details
class="callout"
data-callout="{{ $type }}"
{{ with $fold }}
{{- if eq $fold "+" -}}
open
{{- else if eq $fold "-" }}
{{- /* Default behavior of HTML details tag */}}
{{- else }}
{{- errorf "Callout fold '%s' not supported: %s" $fold $.Position }}
{{- end }}
{{ else -}}
open disabled
{{- end }}
>{{ "" -}}
<summary>
{{- $icon | safeHTML -}}
<span>{{ $summary | markdownify }}</span>
{{- if $fold -}}
<svg xmlns="http://www.w3.org/2000/svg" class="chevron" width="0.75em" height="1.3em" viewBox="0 0 10 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m2 6 6 6-6 6"/></svg>
{{- end -}}
</summary>
{{- with $content := $.InnerDeindent }}
{{- $content | $.Page.RenderString (dict "display" "block") }}
{{- end -}}
</details>
{{- define "partials/callout-icon.html" }}
{{- $type := . -}}
<svg xmlns="http://www.w3.org/2000/svg" class="callout-icon" width="1.2em" height="1.2em" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
{{- if in (slice "note") $type -}}
<line x1="18" y1="2" x2="22" y2="6"></line><path d="M7.5 20.5 19 9l-4-4L3.5 16.5 2 22z"></path>
{{- else if in (slice "abstract" "summary" "tldr") $type -}}
<rect x="8" y="2" width="8" height="4" rx="1" ry="1"></rect><path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"></path><path d="M12 11h4"></path><path d="M12 16h4"></path><path d="M8 11h.01"></path><path d="M8 16h.01"></path>
{{- else if in (slice "info") $type -}}
<circle cx="12" cy="12" r="10"></circle><line x1="12" y1="16" x2="12" y2="12"></line><line x1="12" y1="8" x2="12.01" y2="8"></line>
{{- else if in (slice "todo") $type -}}
<path d="M12 22c5.523 0 10-4.477 10-10S17.523 2 12 2 2 6.477 2 12s4.477 10 10 10z"></path><path d="m9 12 2 2 4-4"></path>
{{- else if in (slice "tip" "hint" "important") $type -}}
<path d="M8.5 14.5A2.5 2.5 0 0 0 11 12c0-1.38-.5-2-1-3-1.072-2.143-.224-4.054 2-6 .5 2.5 2 4.9 4 6.5 2 1.6 3 3.5 3 5.5a7 7 0 1 1-14 0c0-1.153.433-2.294 1-3a2.5 2.5 0 0 0 2.5 2.5z"></path>
{{- else if in (slice "success" "check" "done") $type -}}
<polyline points="20 6 9 17 4 12"></polyline>
{{- else if in (slice "question" "help" "faq") $type -}}
<circle cx="12" cy="12" r="10"></circle><path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"></path><line x1="12" y1="17" x2="12.01" y2="17"></line>
{{- else if in (slice "warning" "caution" "attention") $type -}}
<path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"></path><line x1="12" y1="9" x2="12" y2="13"></line><line x1="12" y1="17" x2="12.01" y2="17"></line>
{{- else if in (slice "failure" "fail" "missing") $type -}}
<line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line>
{{- else if in (slice "danger" "error") $type -}}
<polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"></polygon>
{{- else if in (slice "bug") $type -}}
<rect x="8" y="6" width="8" height="14" rx="4"></rect><path d="m19 7-3 2"></path><path d="m5 7 3 2"></path><path d="m19 19-3-2"></path><path d="m5 19 3-2"></path><path d="M20 13h-4"></path><path d="M4 13h4"></path><path d="m10 4 1 2"></path><path d="m14 4-1 2"></path>
{{- else if in (slice "example") $type -}}
<line x1="8" y1="6" x2="21" y2="6"></line><line x1="8" y1="12" x2="21" y2="12"></line><line x1="8" y1="18" x2="21" y2="18"></line><line x1="3" y1="6" x2="3.01" y2="6"></line><line x1="3" y1="12" x2="3.01" y2="12"></line><line x1="3" y1="18" x2="3.01" y2="18"></line>
{{- else if in (slice "quote" "cite") $type -}}
<path d="M3 21c3 0 7-1 7-8V5c0-1.25-.756-2.017-2-2H4c-1.25 0-2 .75-2 1.972V11c0 1.25.75 2 2 2 1 0 1 0 1 1v1c0 1-1 2-2 2s-1 .008-1 1.031V20c0 1 0 1 1 1z"></path><path d="M15 21c3 0 7-1 7-8V5c0-1.25-.757-2.017-2-2h-4c-1.25 0-2 .75-2 1.972V11c0 1.25.75 2 2 2h.75c0 2.25.25 4-2.75 4v3c0 1 0 1 1 1z"></path>
{{- else }}
{{- errorf "Callout type '%s' not supported: %s" $type $.Position }}
{{- end -}}
</svg>
{{- end }}
{{- define "partials/callout-default-summary.txt" }}
{{ $type := . }}
{{ return partialCached "i18n.txt" $type $type site.Language.LanguageCode }}
{{- end -}}

Here is what it looks like (taking examples from Callouts - Obsidian Help):

{{< callout "info" >}}

Here's a callout block. It supports Markdown, Wikilinks, and embeds!

Engelbart.jpg

{{< /callout >}}

{{< callout type="tip" summary="Callouts can have custom titles" >}}

Like this one

{{< /callout >}}

{{< callout type="tip" summary="Title-only callout" />}}

{{< callout type="faq" fold="-" title="Are callouts foldable?" >}}

Yes! In a foldable callout, the contents are hidden when the callout is collapsed

{{< /callout >}}

{{< callout type="question" title="Can callouts be nested?" >}}

{{< callout type="todo" title="Yes!, they can." >}}

{{< callout type="example" title="You can even use multiple layers of nesting." />}}

{{< /callout >}}

{{< /callout >}}

{{< callout type="done" title="Callouts with markdown" >}}

Before {{< callout type="todo" title="Yes!, they can." >}}

**Before**
{{< callout type="example" title="You can even use multiple layers of nesting." >}}

  **_Inside_**
{{< /callout >}}

**After**

{{< /callout >}}

After

{{< /callout >}}


{{< callout "note" "+" >}}

A note callout

{{< /callout >}}


{{< callout "abstract" "+" >}}

A abstract callout

{{< /callout >}}

{{< callout "summary" "+" >}}

A summary callout

{{< /callout >}}

{{< callout "tldr" "+" >}}

A tldr callout

{{< /callout >}}


{{< callout "info" "+" >}}

A info callout

{{< /callout >}}


{{< callout "todo" "+" >}}

A todo callout

{{< /callout >}}


{{< callout "tip" "+" >}}

A tip callout

{{< /callout >}}

{{< callout "hint" "+" >}}

A hint callout

{{< /callout >}}

{{< callout "important" "+" >}}

A important callout

{{< /callout >}}


{{< callout "success" "+" >}}

A success callout

{{< /callout >}}

{{< callout "check" "+" >}}

A check callout

{{< /callout >}}

{{< callout "done" "+" >}}

A done callout

{{< /callout >}}


{{< callout "question" "+" >}}

A question callout

{{< /callout >}}

{{< callout "help" "+" >}}

A help callout

{{< /callout >}}

{{< callout "faq" "+" >}}

A faq callout

{{< /callout >}}


{{< callout "warning" "+" >}}

A warning callout

{{< /callout >}}

{{< callout "caution" "+" >}}

A caution callout

{{< /callout >}}

{{< callout "attention" "+" >}}

A attention callout

{{< /callout >}}


{{< callout "failure" "+" >}}

A failure callout

{{< /callout >}}

{{< callout "fail" "+" >}}

A fail callout

{{< /callout >}}

{{< callout "missing" "+" >}}

A missing callout

{{< /callout >}}


{{< callout "danger" "+" >}}

A danger callout

{{< /callout >}}

{{< callout "error" "+" >}}

A error callout

{{< /callout >}}


{{< callout "bug" "+" >}}

A bug callout

{{< /callout >}}


{{< callout "example" "+" >}}

A example callout

{{< /callout >}}


{{< callout "quote" "+" >}}

A quote callout

{{< /callout >}}

{{< callout "cite" "+" >}}

A cite callout

{{< /callout >}}

@RemiBardon
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment