Skip to content

Commit a9c6ea8

Browse files
committed
implement a github reference for auto-code blocks
1 parent ae2a6b2 commit a9c6ea8

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed
+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
div.nocode {
1+
.tab-pane .nocode {
22
border-bottom: 1px solid #dee2e6;
33
margin: 2rem 0 2rem 0;
44
padding-bottom: 1rem;
55
}
6+
7+
.tab-pane .github {
8+
text-align: center;
9+
margin: 0 0 1rem 0;
10+
font-weight: 600;
11+
}

website_and_docs/content/documentation/about/style.en.md

+26
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,32 @@ You need to specify which parts are code and which are not yourself now, like th
173173
< ... >
174174
{{</* /tabpane */>}}
175175

176+
### Link to GitHub
177+
178+
If you disable code blocks, you can create whatever kind of link anywhere you want.
179+
But say you want to add a GitHub link associated with a given tab when using the default code block:
180+
{{< tabpane >}}
181+
{{< tab header="Link" github="seleniumhq/seleniumhq.github.io/blob/dev/website_and_docs/content/documentation/about/style.en.md#L205" >}}
182+
Content in automatic code block that refers to something on GitHub
183+
{{< /tab >}}
184+
{{< tab header="No Link" >}}
185+
This content should not get linked to GitHub
186+
{{< /tab >}}
187+
{{< /tabpane >}}
188+
189+
To add a link to a particular tab, pass in a `github` value
190+
to that tab. Note that only the tabs that have this value will have the link added.
191+
192+
{{</* tabpane */>}}
193+
{{</* tab header="Link" github="seleniumhq/seleniumhq.github.io/blob/dev/website_and_docs/content/documentation/about/style.en.md#L205" */>}}
194+
Content in automatic code block that refers to something on GitHub
195+
{{</* /tab */>}}
196+
{{</* tab header="No Link" */>}}
197+
This content should not get linked to GitHub
198+
{{</* /tab */>}}
199+
{{</* /tabpane */>}}
200+
201+
176202
### Code Comments
177203

178204
Minimize code comments because they are difficult to translate.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!-- Make sure that we are enclosed within a tabpane shortcode block -->
2+
{{ with $.Parent }}
3+
{{- if ne $.Parent.Name "tabpane" -}}
4+
{{- errorf "tab must be used within a tabpane block" -}}
5+
{{- end -}}
6+
{{- end -}}
7+
8+
<!-- Prefill header if not given as parameter -->
9+
{{ $header := default (printf "Tab %v" ( add $.Ordinal 1)) (.Get "header") }}
10+
11+
<!-- store all tab info in dict tab -->
12+
{{ $tab := dict "header" $header }}
13+
{{ with $.Get "lang" }}
14+
{{ $tab = merge $tab (dict "language" ($.Get "lang")) }}
15+
{{ end }}
16+
{{ with $.Get "github" }}
17+
{{ $tab = merge $tab (dict "github" ($.Get "github")) }}
18+
{{ end }}
19+
{{ with $.Get "highlight" }}
20+
{{ $tab = merge $tab (dict "highlight" ($.Get "highlight")) }}
21+
{{ end }}
22+
{{ with $.Inner }}
23+
<!-- Trim any leading and trailing newlines from .Inner, this avoids
24+
spurious lines during syntax highlighting -->
25+
{{ $tab = merge $tab (dict "content" (trim $.Inner "\n")) }}
26+
{{ end }}
27+
28+
<!-- add dict tab to parent's scratchpad -->
29+
{{ with .Parent }}
30+
{{- $.Parent.Scratch.SetInMap "tabs" (printf "%v" $.Ordinal) $tab -}}
31+
{{ end }}

website_and_docs/layouts/shortcodes/tabpane.html

+5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@
4949
{{- $entryid := printf "tabs-%v-%v" $.Ordinal $index | anchorize -}}
5050

5151
{{- highlight (index . "content") $lang $hloptions -}}
52+
{{ if $element.github }}
53+
<div class="github nocode">
54+
<a href ="https://www.github.com/{{- $element.github -}}">See full example on GitHub.</a>
55+
</div>
56+
{{end}}
5257
{{end}}
5358

5459
</div>

0 commit comments

Comments
 (0)