Skip to content

Commit 5ab75e2

Browse files
committed
Edits
1 parent 93879ea commit 5ab75e2

File tree

1 file changed

+44
-142
lines changed

1 file changed

+44
-142
lines changed

README.md

Lines changed: 44 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -122,50 +122,51 @@ icon:
122122
> [!NOTE]
123123
> You can highlight important information in your articles or docs using different types of callouts (also known as admonitions – or alerts, as used in [the Hugo docs](https://gohugo.io/render-hooks/blockquotes/#alerts)).
124124
125-
For compatibility with both content and layout files, we use a mix of shortcodes and partials to display blockquote alerts. Partials work in layout, but not content files. Shortcodes work in content, but not layout files. So you'll want to call the partial in layout files but use the shortcode (it calls the partial) in content files.
125+
For compatibility with both content and layout files, we use a mix of shortcodes and partials to display blockquote alerts. Partials work in layout, but not content files. Shortcodes work in content, but not layout files. Use the partial in layout files, and the shortcode (which internally calls the partial) in content files.
126126

127127
The partial is at `site/layouts/partials/blockquote-alert.html`, and the shortcode is at `site/layouts/shortcodes/blockquote-alert.html`.
128128

129-
There are five alert types as shown in the examples below. Omit the `title` parameter to keep the alert type as the default title (for example, a note alert will have "Note" as its title). The descriptions for the alert types are borrowed from the Hugo docs:
129+
There are five available alert types as shown in the examples below:
130130

131-
```
132-
# Shortcodes in content files
131+
- note
132+
- tip
133+
- important
134+
- warning
135+
- caution
136+
137+
Omit the `title` parameter to keep the alert type as the default title (for example, a note alert will have "Note" as its title):
138+
139+
```md
140+
<!-- Shortcodes in content files -->
133141

134142
{{< blockquote-alert type="note" title="Optional custom title">}}
135143
Useful information that users should know, even when skimming content.
136144
{{< /blockquote-alert >}}
137145

138-
----------------
139-
140146
{{< blockquote-alert type="tip" title="Optional custom title">}}
141147
Helpful advice for doing things better or more easily.
142148
{{< /blockquote-alert >}}
143149

144-
----------------
145-
146150
{{< blockquote-alert type="important" title="Optional custom title">}}
147151
Key information users need to know to achieve their goal.
148152
{{< /blockquote-alert >}}
149153

150-
----------------
151-
152154
{{< blockquote-alert type="warning" title="Optional custom title">}}
153155
Urgent info that needs immediate user attention to avoid problems.
154156
{{< /blockquote-alert >}}
155157

156-
----------------
157-
158158
{{< blockquote-alert type="caution" title="Optional custom title">}}
159159
Advises about risks or negative outcomes.
160160
{{< /blockquote-alert >}}
161161
```
162162

163-
For layout files, you can call the partial as shown in the examples below. Just like in the shortcode examples, any string passed into the `content` parameter is interpreted as markdown. Use `html` instead `to pass in HTML. Again, the title parameter is optional and will default to the alert type:
163+
In layout files, call the partial directly. Just like shortcode content, anything passed to the `content` parameter is parsed as Markdown. To pass raw HTML instead, use the `html` parameter. Again, the title parameter is optional and will default to the alert type:
164164

165-
```
166-
# Partials in layout files
165+
```html
166+
<!-- Partials in layout files -->
167+
168+
<!-- Anything passed via `content` is interpreted as Markdown -->
167169

168-
{{/* These are interpreted as Markdown */}}
169170
{{ partial "blockquote-alert.html" (dict
170171
"type" "note"
171172
"title" "Optional custom title"
@@ -195,9 +196,28 @@ For layout files, you can call the partial as shown in the examples below. Just
195196
"title" "Optional custom title"
196197
"content" "Advises about risks or negative outcomes."
197198
) }}
199+
```
200+
201+
In addition to simple string content as shown above, you can also pass in complex nested content with multiple paragraphs and elements:
198202

199-
These are also valid:
203+
```md
204+
<!-- Shortcode example with more complex content -->
200205

206+
{{< blockquote-alert type="tip" title="Optional custom Title" >}}
207+
This is a tip with **bold text** and _italic_ text.
208+
209+
This is a second paragraph in the same alert.
210+
211+
- List item 1
212+
- List item 2
213+
{{< /blockquote-alert >}}
214+
```
215+
216+
You can do similar in partials. These are all valid options. Additionally, you can assign content to a variable before passing it in, which helps with formatting in longer templates:
217+
218+
```html
219+
<!-- You can wrap your markdown content in backticks if it doesn't itself contain backticks -->
220+
<!-- Note that indented lines could be interpreted as a preformatted code block. -->
201221
{{ $alertContent := `This is a tip with **bold text** and _italic_ text.
202222

203223
This is a second paragraph in the same alert.
@@ -212,7 +232,7 @@ This is a second paragraph in the same alert.
212232
"content" $alertContent
213233
) }}
214234

215-
235+
<!-- Concatenate multi-line strings (markdown) -->
216236
{{ $alertContent := add
217237
"This is a tip with **bold text** and _italic_ text.\n\n"
218238
"This is a second paragraph in the same alert.\n"
@@ -226,151 +246,33 @@ This is a second paragraph in the same alert.
226246
"title" "Optional custom title"
227247
"content" $alertContent
228248
) }}
229-
```
230-
231-
You can include simple string content, as shown above, or complex nested content with multiple paragraphs and HTML elements:
232-
233-
```
234-
# Shortcode in content files
235-
236-
{{< blockquote-alert type="tip" title="Optional custom Title" >}}
237-
This is a tip with **bold text** and _italic_ text.
238-
239-
This is a second paragraph in the same alert.
240-
241-
- List item 1
242-
- List item 2
243-
{{< /blockquote-alert >}}
244-
245-
# Partial in layout files
246-
247-
{{ partial "blockquote-alert.html" (dict
248-
"type" "tip"
249-
"title" "Optional custom title"
250-
"content" "<p>Helpful advice for doing things better or more easily.</p>"
251-
) }}
252249

250+
<!-- Pass HTML with nested elements -->
253251
{{ partial "blockquote-alert" (dict
254252
"type" "caution"
255253
"title" "Be Careful!"
256-
"content" "<p>This is a <strong>caution</strong> message.</p><p>It has multiple paragraphs.</p>"
254+
"html" "<p>This is a <strong>caution</strong> message.</p><p>It has multiple paragraphs.</p>"
257255
) }}
258256
```
259257

260-
```
261-
{{ $alertContent := `This is a tip with **bold text** and _italic_ text.
262-
263-
This is a second paragraph in the same alert.
264-
265-
- List item 1
266-
- List item 2
267-
`}}
268-
269-
270-
{{ $alertContent := add
271-
"This is a tip with **bold text** and _italic_ text.\n\n"
272-
"This is a second paragraph in the same alert.\n"
273-
"- List item 1\n"
274-
"- List item 2\n\n"
275-
"`Here's some text in backticks.`"
276-
}}
277-
278-
**NOTE:**
279258

280-
You'll want to handle line breaks properly within the content string in partials when working with complex content. For example, the following will throw a parse error (`html: overlay: parse failed unterminated quoted string in action`):
259+
> [!IMPORTANT]
260+
> When working with complex content, make sure to handle line breaks properly within the strings passed to the `content` or `html` parameters. For example, the following will throw a parse error (`html: overlay: parse failed unterminated quoted string in action`):
281261
282262
```
283263
{{ partial "blockquote-alert" (dict
284264
"type" "caution"
285265
"title" "Be Careful!"
286-
"content" "<p>This is a <strong>caution</strong> message.</p>
266+
"html" "<p>This is a <strong>caution</strong> message.</p>
287267
<p>It has multiple paragraphs.</p>"
288268
) }}
289269
```
290270

291-
To fix this, use either of these options:
271+
To avoid this, you can use either of the following options:
292272

293273
- Keep everything on a single line
294274
- Use string concatenation (whether in a variable or directly)
295275

296-
```
297-
<!-- Option #1: Keep everything on a single line -->
298-
{{ partial "blockquote-alert" (dict
299-
"type" "caution"
300-
"title" "Be Careful!"
301-
"content" "<p>This is a <strong>caution</strong> message.</p><p>It has multiple paragraphs.</p>"
302-
) }}
303-
304-
---------------
305-
<!-- Option #2: Use string concatenation (whether in a variable or directly) -->
306-
307-
{{ $alertContent := add
308-
"<p>This is a <strong>caution</strong> message.</p>"
309-
"<p>It has multiple paragraphs.</p>"
310-
}}
311-
312-
{{ partial "blockquote-alert.html" (dict
313-
"type" "caution"
314-
"title" "Be Careful!"
315-
"content" $alertContent
316-
) }}
317-
318-
This is a tip with **bold text** and _italic_ text.
319-
320-
This is a second paragraph in the same alert.
321-
322-
- List item 1
323-
- List item 2
324-
```\
325-
326-
327-
-------------------------------------------------------
328-
You can pass Markdown through the shortcode or the partial. In fact, if you use the `content` parameter, it's assumed
329-
you've passed either plain text or markdown and your content is treated as such (passed through markdownify).
330-
To pass and have your content be treated as HTML, use the `html` parameter instead.
331-
332-
(Looking for a cleaner, more readable way to format the content so it doesn't include so many tags)
333-
334-
{{ $alertContent := add
335-
"On **Windows**, you will see a message like:\n\n"
336-
"`ZAP_<version>_windows.exe isn't commonly downloaded.`\n\n"
337-
"To circumvent this warning, click **...** → **Keep** → **Show more** → **Keep anyway**.\n\n"
338-
"On **macOS**, you will see a message like:\n\n"
339-
"`\"ZAP.app\" cannot be opened because the developer cannot be verified.`\n\n"
340-
"To circumvent this warning, go to **System Preferences** > **Security & Privacy**. "
341-
"You will see a message saying that \"ZAP\" was blocked. Click **Open anyway** if you trust the installer.\n"
342-
}}
343-
344-
{{ $alertContent := `
345-
On **Windows**, you will see a message like:
346-
347-
`ZAP_<version>_windows.exe isn't commonly downloaded. Make sure you trust ZAP_<version>_windows.exe before you open it.`
348-
349-
To circumvent this warning, you would need to click on **...** and then **Keep**,
350-
then **Show more** and then **Keep anyway**.
351-
352-
On **macOS**, you will see a message like:
353-
354-
`"ZAP.app" cannot be opened because the developer cannot be verified.`
355-
356-
To circumvent this warning, go to **System Preferences** > **Security & Privacy** at the bottom of the dialog.
357-
You will see a message saying that "ZAP" was blocked. If you trust the installer, click **Open anyway**.
358-
` }}
359-
360-
{{ $alertContent := add
361-
"<p><strong>The ZAP releases are currently unsigned</strong></p>"
362-
"<p>On <strong>Windows</strong>, you will see a message like: "
363-
"<code>ZAP_&lt;version&gt;_windows.exe isn't commonly downloaded. Make sure you trust ZAP_&lt;version&gt;_windows.exe before you open it.</code><br>"
364-
"To circumvent this warning, you would need to click on <strong>...</strong> and then <strong>Keep</strong>, then "
365-
"<strong>Show more</strong> and then <strong>Keep anyway</strong>.</p>"
366-
"<p>On <strong>macOS</strong>, you will see a message like: "
367-
"<code>&quot;ZAP.app&quot; cannot be opened because the developer cannot be verified.</code><br>"
368-
"To circumvent this warning, you would need to go to <strong>System Preferences</strong> &gt; <strong>Security & Privacy</strong> at "
369-
"the bottom of the dialog. You will see a message saying that &quot;ZAP&quot; was blocked. Next to it, if you trust the "
370-
"downloaded installer, you can click <strong>Open anyway</strong>.</p>"
371-
}}
372-
-------------------------------------------------------
373-
374276
#### Layouts
375277
For controlling what HTML is rendered, you need to work with the site templates. In the directory, `site/layouts/`, you'll find a number of HTML files with various template tags. The first file to check out is `site/layouts/_default/baseof.html` - this is the base layout Hugo uses to build your site that templates extend. Hugo has a lookup order for associating a content entry to a template. A single entry whose type is post (`type: post`), Hugo will look for a layout in `site/layouts/post/single.html`, and if that does not exist, it will fallback to `site/layouts/_default/single.html`.
376278

0 commit comments

Comments
 (0)