Debian Codegraph @

docs/content/en/methods/shortcode/InnerDeindent.md

raw
1 ---
2 title: InnerDeindent
3 description: Returns the content between opening and closing shortcode tags, with indentation removed, applicable when the shortcode call includes a closing tag.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 returnType: template.HTML
9 signatures: [SHORTCODE.InnerDeindent]
10 ---
11
12 Similar to the [`Inner`][] method, `InnerDeindent` returns the content between opening and closing shortcode tags. However, with `InnerDeindent`, indentation before the content is removed.
13
14 This allows us to effectively bypass the rules governing indentation as provided in the [CommonMark][] specification.
15
16 Consider this Markdown, an unordered list with a small gallery of thumbnail images within each list item:
17
18 ```md {file="content/about.md"}
19 - Gallery one
20
21 {{</* gallery */>}}
22 ![kitten a](thumbnails/a.jpg)
23 ![kitten b](thumbnails/b.jpg)
24 {{</* /gallery */>}}
25
26 - Gallery two
27
28 {{</* gallery */>}}
29 ![kitten c](thumbnails/c.jpg)
30 ![kitten d](thumbnails/d.jpg)
31 {{</* /gallery */>}}
32 ```
33
34 In the example above, notice that the content between the opening and closing shortcode tags is indented by four spaces. Per the CommonMark specification, this is treated as an indented code block.
35
36 With this shortcode, calling `Inner` instead of `InnerDeindent`:
37
38 ```go-html-template {file="layouts/_shortcodes/gallery.html"}
39 <div class="gallery">
40 {{ .Inner | strings.TrimSpace | .Page.RenderString }}
41 </div>
42 ```
43
44 Hugo renders the Markdown to:
45
46 ```html
47 <ul>
48 <li>
49 <p>Gallery one</p>
50 <div class="gallery">
51 <pre><code>![kitten a](images/a.jpg)
52 ![kitten b](images/b.jpg)
53 </code></pre>
54 </div>
55 </li>
56 <li>
57 <p>Gallery two</p>
58 <div class="gallery">
59 <pre><code>![kitten c](images/c.jpg)
60 ![kitten d](images/d.jpg)
61 </code></pre>
62 </div>
63 </li>
64 </ul>
65 ```
66
67 Although technically correct per the CommonMark specification, this is not what we want. If we remove the indentation using the `InnerDeindent` method:
68
69 ```go-html-template {file="layouts/_shortcodes/gallery.html"}
70 <div class="gallery">
71 {{ .InnerDeindent | strings.TrimSpace | .Page.RenderString }}
72 </div>
73 ```
74
75 Hugo renders the Markdown to:
76
77 ```html
78 <ul>
79 <li>
80 <p>Gallery one</p>
81 <div class="gallery">
82 <img src="images/a.jpg" alt="kitten a">
83 <img src="images/b.jpg" alt="kitten b">
84 </div>
85 </li>
86 <li>
87 <p>Gallery two</p>
88 <div class="gallery">
89 <img src="images/c.jpg" alt="kitten c">
90 <img src="images/d.jpg" alt="kitten d">
91 </div>
92 </li>
93 </ul>
94 ```
95
96 [CommonMark]: https://spec.commonmark.org/current/#indented-code-blocks
97 [`Inner`]: /methods/shortcode/inner/