Skip to content

Commit 7fb48b7

Browse files
authored
DOC-581 | Fix Markdown rendering in combination with render hooks (#245)
* Use .Page.RenderString in tip admonition shortcode Hugo has a known issue with the markdownify filter in combination with render hooks (here the one for links), not forwarding the page context correctly * Use .Page.RenderString also for tab content so that relative doc links work * Render example description frontmatter as it may contain Markdown The markdownify filter would be sufficient as we won't be putting relative links in the descriptions but RenderString allows us to preserve the wrapping <p> tag if it's only a single paragraph. Correctly forward context to partials to access .Page * Use .Page.RenderString for expand shortcodes too Don't markdownify example outputs but do so for expand titles. Make expand label non-selectable. * TO BE REVERTED: Test content * Revert "TO BE REVERTED: Test content" This reverts commit 5a0aa9e.
1 parent 31d3649 commit 7fb48b7

File tree

10 files changed

+51
-42
lines changed

10 files changed

+51
-42
lines changed

site/themes/arangodb-docs-theme/layouts/partials/shortcodes/examples/example.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
{{ if $context.Page.Store.Get $name }}
3030
{{ $response := .response | base64Decode | transform.Unmarshal }}
3131
{{- partial "shortcodes/examples/render.html" (dict
32-
"context" .
32+
"context" $context
3333
"content" $response
3434
"options" $options
3535
"language" $language
@@ -73,7 +73,7 @@
7373
{{ with $cacheFound }}
7474
{{ $response := .response | base64Decode | transform.Unmarshal }}
7575
{{- partial "shortcodes/examples/render.html" (dict
76-
"context" .
76+
"context" $context
7777
"content" $response
7878
"options" $options
7979
"language" $language

site/themes/arangodb-docs-theme/layouts/partials/shortcodes/examples/generate.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
{{ if $remote }}
2222
{{ $response := unmarshal $remote.Content }}
2323
{{- partial "shortcodes/examples/render.html" (dict
24-
"context" .
24+
"context" $context
2525
"content" $response
2626
"options" $options
2727
"language" $language
Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
1-
{{ $options := .options }}
2-
{{ $content := .content }}
3-
{{ $language := .language }}
1+
{{- $context := .context }}
2+
{{- $options := .options }}
3+
{{- $content := .content }}
4+
{{- $language := .language }}
45

5-
{{ if eq .language "curl" }}
6-
{{ $language = "bash" }}
7-
{{ end }}
6+
{{- if eq .language "curl" }}
7+
{{- $language = "bash" }}
8+
{{- end }}
89

9-
<p>{{ $options.description }}</p>
10+
{{- /* Ensure that a single paragraph is also wrapped in <p></p> */}}
11+
{{- $options.description | $context.Page.RenderString (dict "display" "block") }}
1012

11-
{{ $input := transform.Highlight $content.input $language }}
13+
{{- $input := transform.Highlight $content.input $language }}
1214
{{ $input }}
1315

14-
{{ if $options.bindVars }}
15-
<strong>Bind Parameters</strong><br>
16-
17-
{{ $bindVars := $options.bindVars | jsonify (dict "indent" " ") }}
16+
{{- if $options.bindVars }}
17+
<strong>Bind Parameters</strong>
18+
<br>
19+
{{- $bindVars := $options.bindVars | jsonify (dict "indent" " ") }}
1820
{{ transform.Highlight $bindVars "json" }}
19-
{{ end }}
21+
{{- end }}
2022

21-
{{ $output := transform.Highlight $content.output $language }}
22-
{{ $block := printf "%s" $output | markdownify}}
23-
{{- partial "shortcodes/expand.html" (dict
24-
"content" $block
25-
"open" "open"
26-
"title" "Show output"
23+
{{- $output := transform.Highlight $content.output $language }}
24+
{{- $block := printf "%s" $output }}
25+
{{- partial "shortcodes/expand.html" (dict
26+
"context" $context
27+
"content" $block
28+
"open" "open"
29+
"title" "Show output"
2730
) }}
28-
<br>
31+
<br>

site/themes/arangodb-docs-theme/layouts/partials/shortcodes/expand.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
{{- $content := .content | markdownify }}
1+
{{- $context := .context }}
2+
{{- $content := .content | $context.Page.RenderString }}
23
{{- $title := .title | default (T "Expand-title") }}
3-
{{- $description := .description }}
44
{{- $expanded := .open | default false }}
55
{{- if eq (printf "%T" $expanded) "string" }}
66
{{- $expanded = (eq $expanded "true") }}
77
{{- end }}
88
{{- with $content }}
99
<div class="expand{{- if $expanded }} expand-expanded{{ end }}">
1010
{{/* things are getting complicated when search tries to open the expand box while jquery sets the display CSS on the element */ -}}
11-
<a class="expand-label" onclick="toggleExpandShortcode(event)">{{ $title }}</a>
11+
<a class="expand-label" onclick="toggleExpandShortcode(event)">{{ $title | markdownify }}</a>
1212
<div class="expand-content" style="display: {{ if $expanded }}block{{ else }}none{{ end }};">
13-
{{ $description | markdownify }}
1413
{{ $content | safeHTML }}
1514
</div>
1615
</div>

site/themes/arangodb-docs-theme/layouts/partials/shortcodes/tabs.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</div>
1414
{{- range $idx, $tab := $tabs }}
1515
<div data-tab-item="{{ .name }}" data-tab-group="{{ $groupid }}" class="tab-item {{ cond (eq $idx 0) "selected" ""}}">
16-
{{- .content | markdownify -}}
16+
{{- .content | $context.Page.RenderString -}}
1717
</div>
1818
{{- end }}
1919
</div>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
{{- $_hugo_config := `{ "version": 1 }` }}
1+
{{- $_hugo_config := `{ "version": 1 }` }}{{/* TODO: What does this do? */}}
22
{{- partial "shortcodes/expand.html" (dict
3+
"context" .
34
"content" .Inner
45
"open" (.Get "open" | default (.Get 1))
56
"title" (.Get "title" | default (.Get 0))
6-
"description" (.Get "description" | default (""))
77
) }}

site/themes/arangodb-docs-theme/layouts/shortcodes/program-options.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{- $context := . }}
12
{{- $program := .Get "name" }}
23
{{- $pageVersion := .Page.Store.Get "versionShort" }}
34
{{- $dataFolderByVersion := index site.Data $pageVersion }}
@@ -26,17 +27,18 @@
2627

2728
{{- $section := index $optionsMap "General" }}
2829
{{- if gt ($section | len) 0 }}
29-
{{- template "render-section" (dict "name" "General" "section" $section) }}
30+
{{- template "render-section" (dict "name" "General" "section" $section "context" $context) }}
3031
{{- end }}
3132

3233
{{- range $name, $section := $optionsMap }}
3334
{{- if ne $name "General" }}
34-
{{- template "render-section" (dict "name" $name "section" $section) }}
35+
{{- template "render-section" (dict "name" $name "section" $section "context" $context) }}
3536
{{- end }}
3637
{{- end }}
3738
{{- end }}
3839

3940
{{- define "render-section" }}
41+
{{- $context := .context }}
4042
## {{ .name }}
4143

4244
{{ range $option := .section }}
@@ -96,6 +98,7 @@ Effective on {{ delimit . ", " " and " }} only.
9698

9799
{{ with $option.longDescription }}
98100
{{- partial "shortcodes/expand.html" (dict
101+
"context" $context
99102
"content" .
100103
"open" "open"
101104
"title" "Show details"

site/themes/arangodb-docs-theme/layouts/shortcodes/tip.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<div class="box-content">
44
<i class="fas fa-check"></i>
55
<div class="box-text">
6-
{{ .InnerDeindent | markdownify }}
6+
{{ .InnerDeindent | .Page.RenderString }}
77
</div>
88
</div>
99
</div>

site/themes/arangodb-docs-theme/static/css/theme.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1657,7 +1657,11 @@ blockquote p {
16571657

16581658
.expand-label {
16591659
font-size: 1.1rem;
1660-
1660+
cursor: pointer;
1661+
-webkit-user-select: none;
1662+
-moz-user-select: none;
1663+
-ms-user-select: none;
1664+
user-select: none;
16611665
}
16621666

16631667
.expand-label::before {

site/themes/arangodb-docs-theme/static/js/theme.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -449,14 +449,14 @@ function copyURI(evt) {
449449
}
450450

451451
function toggleExpandShortcode(event) {
452-
var t = $(event.target)
453-
if(t.parent('.expand-expanded.expand-marked').length){
454-
t.next().css('display','none')
455-
}else if(t.parent('.expand-marked').length){
456-
t.next().css('display','block') }
457-
else{
458-
t.next('.expand-content').slideToggle(100);
459-
}
452+
var t = $(event.target.closest("a"));
453+
if (t.parent('.expand-expanded.expand-marked').length) {
454+
t.next().css('display','none');
455+
} else if (t.parent('.expand-marked').length) {
456+
t.next().css('display','block')
457+
} else {
458+
t.next('.expand-content').slideToggle(100);
459+
}
460460
t.parent().toggleClass('expand-expanded');
461461
}
462462

0 commit comments

Comments
 (0)