Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tomlToTable #548

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions layouts/shortcodes/figure.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,36 @@
width = 200
caption = 'A figure is an image with a caption and/or a legend:'
legend = '''
**TODO: need to convert yamltotable to tomltotable**
{{< tomlToTable >}}

[[row]]
type = 'header'

[[row.column]]
body = 'Project'

[[row.column]]
body = 'Available Packages'

[[row]]

[[row.column]]
body = 'NumPy'

[[row.column]]
body = '''Official *source code* (all platforms) and *binaries* for<br />
**Windows**, **Linux**, and **Mac OS X**'''

[[row]]

[[row.column]]
body = 'SciPy'

[[row.column]]
body = '''Official *source code* (all platforms) and *binaries* for<br />
**Windows**, **Linux**, and **Mac OS X**'''

{{< /tomlToTable >}}

This paragraph is also part of the legend.
'''
Expand Down Expand Up @@ -46,7 +75,9 @@
</span><a class="headerlink" href="#{{ $id }}" title="Link to this image">#</a></p>
{{- with $figure.legend }}
<div class="legend">
{{ . | markdownify -}}
{{- with (trim . "\n") }}
{{ . | safeHTML }}
{{- end }}
</div>
{{- end }}
</figcaption>
Expand Down
68 changes: 68 additions & 0 deletions layouts/shortcodes/tomlToTable.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{{/*

doc: Render TOML to an HTML table.

{{< tomlToTable >}}

[[row]]
type = 'header'

[[row.column]]
body = 'Project'

[[row.column]]
body = 'Available Packages'

[[row.column]]
body = 'Download location'

[[row]]

[[row.column]]
body = 'NumPy'

[[row.column]]
body = '''Official *source code* (all platforms) and *binaries* for<br />
**Windows**, **Linux**, and **Mac OS X**'''

[[row.column]]
body = '[PyPi page for NumPy](https://pypi.python.org/pypi/numpy)'

[[row]]

[[row.column]]
body = 'SciPy'

[[row.column]]
body = '''Official *source code* (all platforms) and *binaries* for<br />
**Windows**, **Linux**, and **Mac OS X**'''

[[row.column]]
align = 'right'
body = '''[SciPy release page](https://github.com/scipy/scipy/releases) (sources)<br />
[PyPI page for SciPy](https://pypi.python.org/pypi/scipy) (all)'''

{{< /tomlToTable >}}

*/}}

{{ $arg := .Get 0 }}
{{ $data := .Inner | transform.Unmarshal }}

{{ with $data }}
<table>
{{ range $row := .row }}
<tr>
{{ $el := "td" }}
{{ if (eq $row.type "header") }}
{{ $el = "th" }}
{{ end }}
{{ range $col := .column }}
{{ printf "<%s" $el | safeHTML }} colspan="{{ $col.colspan }}" rowspan="{{ $col.rowspan }}" {{ printf ">" | safeHTML }}
{{ $col.body | markdownify }}
{{ printf "</%s>" $el | safeHTML }}
{{ end }}
</tr>
{{ end }}
</table>
{{ end }}