-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathtomlToTable.html
More file actions
91 lines (81 loc) · 2.69 KB
/
tomlToTable.html
File metadata and controls
91 lines (81 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
{{/*
doc: Render TOML to an HTML table.
{{< tomlToTable >}}
caption = 'Table caption'
align = ["left", "left", "right"]
width = "80%"
widths = ["10%", "50%", "20%"]
headerrows = 1
footer-rows = 3
stubcolumns = 1
[[row]]
column = [
"Project",
"Available Packages",
"Download location"
]
[[row]]
column = [
"NumPy",
"Official *source code* (all platforms) and *binaries* for<br/>\n**Windows**, **Linux**, and **Mac OS X**\n",
"[PyPi page for NumPy](https://pypi.python.org/pypi/numpy)"
]
[[row]]
column = [
"SciPy",
"Official *source code* (all platforms) and *binaries* for<br/>\n**Windows**, **Linux** and **Mac OS X**\n",
"[SciPy release page](https://github.com/scipy/scipy/releases) (sources)<br/>\n[PyPI page for SciPy](https://pypi.python.org/pypi/scipy) (all)\n"
]
{{< /tomlToTable >}}
*/}}
{{- $data := .Inner | transform.Unmarshal }}
{{- $id := printf "id%03d" $.Ordinal -}}
{{- $align := $data.align }}
{{- $numrows := $data.row | len }}
{{- $headerrows := or $data.headerrows 0 }}
{{- $header := first $headerrows $data.row }}
{{- $body := last (math.Sub $numrows $headerrows) $data.row }}
<table class="table" id="{{ $id }}" {{- with $data.width }}style="width: {{ . }}"{{- end }}>
{{- with $data.caption }}
<caption><span class="caption-text">{{ . }}</span><a class="headerlink" href="#{{ $id }}" title="Link to this table">#</a></caption>
{{- end }}
{{- with $data.widths }}
<colgroup>
{{- range . }}
<col style="width: {{ . }}" />
{{- end }}
</colgroup>
{{ end }}
{{- if $header }}<thead>
{{- range $row_idx, $row := $header }}
{{ if (modBool $row_idx 2) }}<tr class="row-odd">{{- else }}<tr class="row-even">{{- end }}
{{- range $col_idx, $col := $row.column }}
{{- $alignment := or (index $align $col_idx) "left" }}
{{- $isStub := compare.Lt $col_idx $data.stubcolumns }}
{{- $class := cond $isStub "head stub" "head" }}
<th class="{{ $class }}" style="text-align:{{ $alignment }}">
{{ $col | markdownify }}
</th>
{{- end }}
</tr>
{{- end }}
</thead>
{{- end }}
<tbody>
{{- range $row_idx, $row := $body }}
{{ if (modBool (add $row_idx $headerrows) 2) }}<tr class="row-odd">{{- else }}<tr class="row-even">{{- end }}
{{- range $col_idx, $col := $row.column }}
{{- $alignment := or (index $align $col_idx) "left" }}
{{- $isStub := compare.Lt $col_idx $data.stubcolumns }}
{{- if $isStub }}
<th class="stub" style="text-align:{{ $alignment }}">
{{- else }}
<td style="text-align:{{ $alignment }}">
{{- end }}
{{ $col | markdownify }}
{{ cond $isStub "</th>" "</td>" | safeHTML }}
{{- end }}
</tr>
{{- end }}
</tbody>
</table>