mirror of
https://github.com/thegeeklab/hugo-geekdoc.git
synced 2024-11-28 15:40:36 +00:00
fix: fix formatting issue while using nested toc shortcodes (#415)
This commit is contained in:
parent
6ab98d1da3
commit
6b464202c9
@ -6,7 +6,7 @@ Hint shortcode can be used as hint/alerts/notification block.
|
|||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
|
|
||||||
| Name | Usage | default |
|
| Name | Usage | Default |
|
||||||
| ---------------- | --------------------------------------------------------------------------------- | --------------------- |
|
| ---------------- | --------------------------------------------------------------------------------- | --------------------- |
|
||||||
| type | color types to choose from | note |
|
| type | color types to choose from | note |
|
||||||
| icon (optional) | custom icon to use | undefined (type name) |
|
| icon (optional) | custom icon to use | undefined (type name) |
|
||||||
|
@ -43,7 +43,7 @@ If you need more flexibility for your embedded images, you could use the `img` s
|
|||||||
|
|
||||||
**Attributes:**
|
**Attributes:**
|
||||||
|
|
||||||
| Name | Usage | default |
|
| Name | Usage | Default |
|
||||||
| ------------- | ------------------------------------------------------------------------------------------------------------- | ----------------- |
|
| ------------- | ------------------------------------------------------------------------------------------------------------- | ----------------- |
|
||||||
| name (string) | Name of the image resource defined in your front matter. | empty |
|
| name (string) | Name of the image resource defined in your front matter. | empty |
|
||||||
| alt (string) | Description for displayed image. | resource `.Title` |
|
| alt (string) | Description for displayed image. | resource `.Title` |
|
||||||
|
@ -14,7 +14,7 @@ Include shortcode can include files of different types. By specifying a language
|
|||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
|
|
||||||
| Name | Usage | default |
|
| Name | Usage | Default |
|
||||||
| -------- | ----------------------------------------------------------------------------------------------------------------------------------- | -------------------------------- |
|
| -------- | ----------------------------------------------------------------------------------------------------------------------------------- | -------------------------------- |
|
||||||
| file | path to the included file relative to the Hugo root | undefined |
|
| file | path to the included file relative to the Hugo root | undefined |
|
||||||
| language | language for [syntax highlighting](https://gohugo.io/content-management/syntax-highlighting/#list-of-chroma-highlighting-languages) | undefined |
|
| language | language for [syntax highlighting](https://gohugo.io/content-management/syntax-highlighting/#list-of-chroma-highlighting-languages) | undefined |
|
||||||
|
@ -4,12 +4,22 @@ title: ToC
|
|||||||
|
|
||||||
Simple wrapper to generate a page Table of Content from a shortcode.
|
Simple wrapper to generate a page Table of Content from a shortcode.
|
||||||
|
|
||||||
|
**Attributes:**
|
||||||
|
|
||||||
|
| Name | Usage | Default |
|
||||||
|
| ------ | -------------------------- | ------------------------------------------------------------- |
|
||||||
|
| format | format of the returned ToC | <!-- spellchecker-disable -->html<!-- spellchecker-enable --> |
|
||||||
|
|
||||||
|
**Syntax:**
|
||||||
|
|
||||||
<!-- prettier-ignore-start -->
|
<!-- prettier-ignore-start -->
|
||||||
```tpl
|
```tpl
|
||||||
{{</* toc */>}}
|
{{</* toc (format=[html|raw]) */>}}
|
||||||
```
|
```
|
||||||
<!-- prettier-ignore-end -->
|
<!-- prettier-ignore-end -->
|
||||||
|
|
||||||
|
**Example:**
|
||||||
|
|
||||||
{{< toc >}}
|
{{< toc >}}
|
||||||
|
|
||||||
## Level 1
|
## Level 1
|
||||||
|
@ -6,6 +6,6 @@
|
|||||||
</label>
|
</label>
|
||||||
<input id="{{ $id }}-{{ .Ordinal }}" type="checkbox" class="gdoc-expand__control hidden" />
|
<input id="{{ $id }}-{{ .Ordinal }}" type="checkbox" class="gdoc-expand__control hidden" />
|
||||||
<div class="gdoc-markdown--nested gdoc-expand__content">
|
<div class="gdoc-markdown--nested gdoc-expand__content">
|
||||||
{{ .Inner | $.Page.RenderString }}
|
{{ .Inner | $.Page.RenderString | htmlUnescape | safeHTML }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,41 +1,39 @@
|
|||||||
{{ $tocLevels := default (default 6 .Site.Params.GeekdocToC) .Page.Params.GeekdocToC }}
|
{{- $tocLevels := default (default 6 .Site.Params.GeekdocToC) .Page.Params.GeekdocToC }}
|
||||||
|
|
||||||
{{ if $tocLevels }}
|
{{- if $tocLevels }}
|
||||||
<div class="gdoc-toc gdoc-toc__level--{{ $tocLevels }}">
|
<div class="gdoc-toc gdoc-toc__level--{{ $tocLevels }}">
|
||||||
{{ template "toc-tree" dict "sect" .Page.Pages }}
|
{{ template "toc-tree" dict "sect" .Page.Pages }}
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{- end }}
|
||||||
|
|
||||||
|
|
||||||
<!-- templates -->
|
<!-- templates -->
|
||||||
{{ define "toc-tree" }}
|
{{- define "toc-tree" }}
|
||||||
<ul>
|
<ul>
|
||||||
{{ range .sect.GroupBy "Weight" }}
|
{{- range .sect.GroupBy "Weight" }}
|
||||||
{{ range .ByTitle }}
|
{{- range .ByTitle }}
|
||||||
{{ if or (not .Params.GeekdocHidden) (not (default true .Params.GeekdocHiddenTocTree)) }}
|
{{- if or (not .Params.GeekdocHidden) (not (default true .Params.GeekdocHiddenTocTree)) }}
|
||||||
<li>
|
<li>
|
||||||
{{ if or .Content .Params.GeekdocFlatSection }}
|
{{- if or .Content .Params.GeekdocFlatSection }}
|
||||||
<span>
|
<span>
|
||||||
<a href="{{ .RelPermalink }}" class="gdoc-toc__entry">
|
<a href="{{ .RelPermalink }}" class="gdoc-toc__entry">
|
||||||
{{ partial "utils/title" . }}{{ with .Params.GeekdocDescription }}:{{ end }}
|
{{- partial "utils/title" . }}{{ with .Params.GeekdocDescription }}:{{ end }}
|
||||||
</a>
|
</a>
|
||||||
{{ with .Params.GeekdocDescription }}{{ . }}{{ end }}
|
{{- with .Params.GeekdocDescription }}{{ . }}{{ end }}
|
||||||
</span>
|
</span>
|
||||||
{{ else }}
|
{{- else -}}
|
||||||
<span>
|
<span>
|
||||||
{{ partial "utils/title" . }}{{ with .Params.GeekdocDescription }}
|
{{- partial "utils/title" . }}{{ with .Params.GeekdocDescription }}: {{ . }}{{ end }}
|
||||||
: {{ . }}
|
|
||||||
{{ end }}
|
|
||||||
</span>
|
</span>
|
||||||
{{ end }}
|
{{- end -}}
|
||||||
|
|
||||||
{{ $numberOfPages := (add (len .Pages) (len .Sections)) }}
|
{{- $numberOfPages := (add (len .Pages) (len .Sections)) }}
|
||||||
{{ if and (ne $numberOfPages 0) (not .Params.GeekdocFlatSection) }}
|
{{- if and (ne $numberOfPages 0) (not .Params.GeekdocFlatSection) }}
|
||||||
{{ template "toc-tree" dict "sect" .Pages }}
|
{{- template "toc-tree" dict "sect" .Pages }}
|
||||||
{{ end }}
|
{{- end }}
|
||||||
</li>
|
</li>
|
||||||
{{ end }}
|
{{- end }}
|
||||||
{{ end }}
|
{{- end }}
|
||||||
{{ end }}
|
{{- end }}
|
||||||
</ul>
|
</ul>
|
||||||
{{ end }}
|
{{- end }}
|
||||||
|
@ -1,8 +1,13 @@
|
|||||||
{{ $tocLevels := default (default 6 .Site.Params.GeekdocToC) .Page.Params.GeekdocToC }}
|
{{- $format := default "html" (.Get "format") }}
|
||||||
|
{{- $tocLevels := default (default 6 .Site.Params.GeekdocToC) .Page.Params.GeekdocToC }}
|
||||||
|
|
||||||
{{ if and $tocLevels .Page.TableOfContents }}
|
{{- if and $tocLevels .Page.TableOfContents -}}
|
||||||
|
{{- if not (eq ($format | lower) "raw") -}}
|
||||||
<div class="gdoc-toc gdoc-toc__level--{{ $tocLevels }}">
|
<div class="gdoc-toc gdoc-toc__level--{{ $tocLevels }}">
|
||||||
{{ .Page.TableOfContents }}
|
{{ .Page.TableOfContents }}
|
||||||
<hr />
|
<hr />
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{- else -}}
|
||||||
|
{{ .Page.TableOfContents }}
|
||||||
|
{{- end -}}
|
||||||
|
{{- end -}}
|
||||||
|
Loading…
Reference in New Issue
Block a user